Why the the code (1) is not result an error while code (2) (3) will?
I think when the subclass calls the constructor, it will calls super class constructor first, but I do not know why the code (1) is right while other two are wrong.
//(1)
public class Parent {
public int a;
public Parent() {
this.a = 0;
}
}
public class Child extends Parent {
public Child() {}
}
//(2)
public class Parent {
public int a;
public Parent(int number) {
this.a = number;
}
}
public class Child extends Parent {
public Child() {}
}
//(3)
public class Parent {
public int a;
public Parent(int number) {
this.a = number;
}
}
public class Child extends Parent {
public Child(int numb) {
}
}
Code(1) is right while other two are wrong.