1.方法重写
public class InheritenceTest2
{
public static void main(String[] args)
{
Dog dog = new Dog();
dog.run();
}
}
class Animal
{
public void run()
{
System.out.println("animal is running");
}
}
class Dog extends Animal
{
public void run()
{
System.out.println("dog is running");
super.run();//调用父类的run方法
}
}
-
public class InheritenceTest3
{
public static void main(String[] args)
{
Son son = new Son();
}
}class Grandpa
{
public Grandpa()
{
System.out.println("grandpa");
}
}class Father extends Grandpa
{
public Father()
{
System.out.println("father");
}
}class Son extends Father
{
public Son()
{
System.out.println("son");
}
}