多态的理解

一、多态中的变量

多态是一个对象两种形态,

class Person

{

  int num=3;

}

class Work

{

  int num=4;

}

Person p=new  Worker ();

p.num的结果为3

二、多态的方法

class Fu
{
    void show()
    {
        System.out.println("fu run");
    }
}

class Zi extends Fu
{
    void show()
    {
        System.out.println("zi run");
    }
}

class  MethodDemo
{
    public static void main(String[] args) 
    {
        Fu f=new Zi();
        f.show();
        System.out.println("Hello World!");
    }
}

三、多态中的静态方法

将上代码fu和zi类中的方法改为static类型时,则调用父的show方法。

总结一下以上三个

原文地址:https://www.cnblogs.com/lzhp/p/3123129.html