class myPerson_5
{
private String name;
private int age;
myPerson_5(String name,int age)
{
this.name=name;
this.age= age;
System.out.println("fu 1");
}
myPerson_5(String name)
{
this.name=name;
//this.age= age;
System.out.println("fu 2");
}
myPerson_5(int age)
{
//this.name=name;
this.age= age;
System.out.println("fu 3");
}
public void setAge(int age)
{
this.age= age;
System.out.println("setAge run");
}
public int getAge()
{
System.out.println("getAge run");
return age;
}
public void setName(String name)
{
this.name= name;
System.out.println("setName run");
}
public String getName()
{
System.out.println("getName run");
return name;
}
}
class myStudent_5 extends myPerson_5
{
public myStudent_5(String name,int age)
{
super(name,age);
System.out.println("studeng run");
}
}
class myWorker_5 extends myPerson_5
{
public myWorker_5(String name)
{
super(name);
System.out.println("work run");
}
}
class myJichengDemo_4
{
public static void main(String[] args)
{
myStudent_5 stu = new myStudent_5("lisi",25);
myWorker_5 wor = new myWorker_5("lisi");
System.out.println(stu.getName());
System.out.println(wor.getName());
}
}
终于把继承中构造函数调用过程弄明白,给每个函数弄个打印语句,怎么执行一清二楚。 |