父类程序:
package HelloWorldf;
public class HelloWorld {
public int age=20;
public String name;
public void show() {
System.out.println("姓名:"+name+"年龄:"+age+"你有会叫的功能");
}
public HelloWorld() {
System.out.println("年纪:"+age);
age=3;
}
}
子类程序:
package HelloWorldf;
public class HelloWorldt extends HelloWorld {
}
测试程序:
package HelloWorldf;
public class test {
public static void main(String[] args) {
// TODO Auto-generated method stub
HelloWorldt two=new HelloWorldt();
two.name="dog";
two.show();
HelloWorld eat=new HelloWorld();
}
}
运行结果:
年纪:20
姓名:dog年龄:3你有会叫的功能
年纪:20
风中打伞的小孩
相关分类