//父类
public class Father{
//父类有一个打孩子方法
public void hitChild(){}
}
//子类1
public class Son1 extends Father{
//重写父类打孩子方法
public void hitChild(){
System.out.println("为什么打我?我做错什么了!"); }
}
//子类2
public class Son2 extends Father{
//重写父类打孩子方法 public void hitChild(){
System.out.println("我知道错了,别打了!"); }
}
//子类3
public class Son3 extends Father{
//重写父类打孩子方法 public void hitChild(){
System.out.println("我跑,你打不着!"); }
}
//测试类
public class Test{
public static void main(String args[]){
Father father;
father = new Son1();
father.hitChild();
father = new Son2();
father.hitChild();
father = new Son3();
father.hitChild();
}
}
//新接口
public interface PetInterFace{
//新功能方法 public void pet();
}
//二代子类
public class Son11 extends Son1 implements PetInterFace{
//实现接口方法
public void pet(){
System.out.println("父亲很爱我!");
}
}