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();
    }
    }

    编译错误。

  • 相关阅读:
    Es module vs require
    phaser3 画虚线实现
    新的计划
    [转]Boostrap Table的refresh和refreshOptions区别
    Storing Java objects in MySQL blobs
    【转】Ubuntu下搜狗输入法突然无法输入中文
    团队作业六
    团队作业七
    团队作业四
    团队作业三
  • 原文地址:https://www.cnblogs.com/wangjiyuan/p/knowledge.html
Copyright © 2011-2022 走看看