Skip to content
Advertisement

Why does super() not get called in the other constuctor?

If both House() and House(name) are called then why is not “Building” printed two times, but instead one time?

JavaScript

Output:

JavaScript

Advertisement

Answer

House(String name) calls this() which is the same as House(). House() implicitly calls super() which is the same as Building().

You never call Building(String name).

House(String name) could call super(name) to do that.

Advertisement