覆盖

class Grandparent {

    public void say(){
       System.out.println("Hello Grandparent");
    }

}



class Parent extends Grandparent{
    public void say() {
       super.say();
    }

}



class Child extends Parent
{


    public void say()
    {

       System.out.println("Hello Child");

    }

}



public class TestInherits
{


    public static void main(String []args)
    {
       Parent b=new Parent();
       Child c = new Child();
       b.say();
       c.say();

    }

}

 

 
 
 
posted @ 2023-10-14 17:51  不会JAVA的小袁  阅读(18)  评论(0编辑  收藏  举报