Only one of these calls (this(.) or super(.)) can appear as the first statement in a single constructor After creating an object of child class we have first called a method from child class and then called a method from the parent class This allows multiple constructors to share setup logic without duplication.
Tiara (@tiarasworldxo) • Instagram photos and videos
When a subclass is instantiated, its constructor implicitly invokes the constructor of its superclass using super ()
This ensures that the superclass part of the object is properly initialized before the subclass constructor proceeds with its initialization logic.
Understand that calling this () within a constructor does not call super () directly It's merely a mechanism for constructor chaining within the same class If you need the superclass constructor to be invoked, ensure to explicitly call super () if not done so by the system during this () calls. You must use the keyword super to call the superclass constructor, and the call must be the first statement in the constructor
Invoking a superclass constructor’s name in a subclass causes a syntax error. This happens implicitly when a subclass is constructed Its first task is to call its parent's constructor method But programmers can also call another constructor explicitly using the keywords this () or super ().
But if you want to invoke parameterized constructor of base class from either default constructor or parameterized constructor, then keyword super is used
Remember, the statement consisting super must be the first statement within constructor.