1 package T0408; 2 3 public class Dad { 4 String name; 5 int age; 6 public Dad(String name,int age){ //有参构造函数 7 this.name = name; 8 this.age = age; 9 }10 public void EatFood(){11 System.out.println("爸爸一天要吃八碗饭,喜欢吃土豆和肉");12 } 13 public void EarnMoney(int money){14 System.out.println("爸爸赚钱的钱数:"+money+"元");15 }16 public void Sleep(){ 17 System.out.println("爸爸一天至少睡多少八小时!"); 18 }19 public static void main(String[] args) {20 Son s = new Son("邹玲",21);21 Dad d = new Dad("邹玲",21);22 s.EarnMoney(8000);23 s.Dancing();24 s.Singing();25 d.EarnMoney(5000);26 d.EatFood();27 d.Sleep();28 29 }30 }31 /* *************************** */32 package T0408;33 34 public class Son extends Dad {//子类继承父类中的一切属性及方法(私有的除外)35 36 public Son(String name, int age) {37 super(name, age);38 // TODO Auto-generated constructor stub39 }40 public void Singing(){41 System.out.println("儿子喜欢唱歌");42 }43 public void Dancing(){44 System.out.println("儿子喜欢跳舞");45 }46 public void EarnMoney(int money){//重写父类的赚钱的方法47 48 System.out.println("儿子赚钱的钱数:"+money+"元");49 }50 }