class HelloA{
public HelloA(){
System.out.println("HelloA");
}
{
System.out.println("I'm A Class");
}
}
class HelloB extends HelloA{
public HelloB(){
//super(); // 调用父类构造函数(1)
System.out.println("HelloB");
}
{
System.out.println("I'm B Class");
}
}
public class TestHelloB{
public static void main(String[] args) {
new HelloB();
}
}
public class TestFatherChild {
public static void main(String[] args) {
Father f = new Father();//(1)
Child c = new Child();//(2)
}
}
class Father {
public Father(){
System.out.println("father");
}
}
class Child extends Father{
public Child(){
System.out.println("child");
}
}
public class Test01 {
public static void main(String[] args) {
new Child("mike");
}
}
class People {
private String name;
public People() {
System.out.print("1");
}
public People(String name) {
System.out.print("2");
this.name = name;
}
}
class Child extends People {
People father;
public Child(String name) {
System.out.print("3");
father = new People(name + " F");
}
public Child() {
System.out.print("4");
}
}
1、进入child类---->super()---->进入People类无参
2、输出1---->回到child类----->
3、输出3----->new People
4、进入Peoper有参---->输出2---->name =mikeF