package com.Hanqi2; public class _1 { public _1() { } public String xingming; public String renzhong; public int age; public _1(String xingming, String renzhong,int age) { System.out.println(xingming + "是一个" + renzhong + "," + age + "岁了"); } //成长 public void chengzhang(int chengzhang) { age += chengzhang; System.out.println(chengzhang + "年后他" + age + "岁了"); } }
package com.Hanqi2; public class _2 extends _1{ public _2(String xingming,String renzhong,int age) { super(xingming,renzhong,age); } public _2() { } public void chengzhang(int grew) { age += grew; System.out.println(grew + "yeas ago,he is " + age); } }
package com.Hanqi2; public class _3 { public static void main(String[] args) { // TODO Auto-generated method stub _1 body = new _1("mading","白种人",25); body.age = 25; body.chengzhang(9); _1 b1 = new _2(); b1.age = 15; b1.chengzhang(1); } }
结果为 :
mading是一个白种人,25岁了
9年后他34岁了
1yeas ago,he is 16