Explanation of output
- by Anon
My program
class Building {
Building() {
System.out.print("b ");
}
Building(String name) {
this();
System.out.print("bn " + name);
}
};
public class House extends Building {
House() {
System.out.print("h "); // this is line# 1
}
House(String name) {
this(); // This is line#2
System.out.print("hn " + name);
}
public static void main(String[] args) {
new House("x ");
}
}
We know that compiler will write a call to super() as the first line in the child class's constructor. Therefore should not the output be:
b (call from compiler written call to super(), before line#2
b (again from compiler written call to super(),before line#1 )
h hn x
But the output is
b h hn x
Why is that?