It prints:
Super Sub
When inheriting from another class, super() has to be called first in the constructor. If not, the compiler will insert that call. This is why super constructor is also invoked when a Sub object is created.
This doesn't create two objects, only one Sub object. The reason to have super constructor called is that if super class could have private fields which need to be initialized by its constructor.
After compiler inserts the super constructor, the sub class constructor looks like the following:
No comments:
Post a Comment