zoukankan      html  css  js  c++  java
  • 多态的思考

    abstract class Father{
        abstract void show();
    }
    
    class Son extends Father
    {
        public void show(){
            System.out.println("I am son.");
        }
    }
    public class start {
    public static void main(String[] args)
    {
        Father son=new Son();
        son.show();
    }
    }

    输出结果为:

    I am son.

    *******************************************************************************************************************************

    class Father{
        public void show(){
            System.out.println("I am father.");
        }
    }
    
    class Son extends Father
    {
        public void show(){
            System.out.println("I am son.");
        }
    }
    public class start {
    public static void main(String[] args)
    {
        Father son=new Son();
        son.show();
    }
    }

    输出结果为:

    I am son.

    *******************************************************************************************************************************

    class Father{
        
    }
    
    class Son extends Father
    {
        public void show(){
            System.out.println("I am son.");
        }
    }
    public class start {
    public static void main(String[] args)
    {
        Father son=new Son();
        son.show();
    }
    }

    编译错误。

  • 相关阅读:
    怎么获取数组中的对象的某一项之和
    原型链
    js的事件循环(Eventloop) 机制/js的宏任务微任务执行顺序
    怎么替换数组中对象的属性
    求对象所有值的和
    sequelize中duplicating:false的使用
    WebSocket
    轮播

    ssl tsl
  • 原文地址:https://www.cnblogs.com/wangjiyuan/p/knowledge.html
Copyright © 2011-2022 走看看