package com.OOP;
public class Application01 {
public static void main(String[] args) {
//对象能执行哪些方法是与左边的类型有关;
Son s1 = new Son();
s1.test();
Father s2 = new Son();//这就是方法test的多态,且只有继承关系才能转换
//父类引用指向子类对象
s2.test();//方法进行重写,
s1.eat();
s2.eat();
//当父类中独有该方法时,使用父类中的方法
//当父类和子类中都有该方法时,也就等于子类重写了父类,使用子类中的方法
}
//static不能重写所以不存在多态
//final是常量
//private方法是私有方法子类无法重写私有的父类
}
package com.OOP;
public class Father {
public void test(){
System.out.println("努力工作");
}
public void eat(){
System.out.println("吃得多");
}
}
package com.OOP;
public class Son extends Father{
@Override
public void eat(){
System.out.println("吃得少");
}
public void test() {
System.out.println("认真上学");;
}
}