借用李高翔朋友的代码,问一个问题 。谢谢
class Person {
public Person() {
func();
}
public void func() {
System.out.print("1,");
}
}
class Teacher extends Person {
public Teacher() {
System.out.println("........");
}
public Teacher(int a) {
//super();
this();
System.out.println(a);
}
public void func() {
System.out.println("2,");
}
public static void main(String[] args) {
// Teacher t1 = new Teacher();
Teacher t2 = new Teacher(3);
}
}
在public Teacher(int a)方法中加入this(),结果
2,
........
3
new Teacher(3)是不是和new String("abc")一样有两个对象。还是其他。希望大家帮忙。 |