+ 1
Why we need to call super() method in default constructor?? why we need to parent class constructor ?? why it is compulsory?
5 Antworten
+ 12
Do you agree, that a child can only exist if it's parents existed before?
Same for child and parent classes ;)
+ 3
when we put super() into a subclass it explicitly calls the superclass constructor. If we omit the call with super() there will be an implicit call to the Object class constructor(in superclasses). because all classes inherit from the Object class. This occurs regardless of whether I put (in superclass)extends Object or not.
+ 2
@tashi awesome answer
+ 2
but answering your question , this is mandatory because basically the superclass needs to have your variables initialized. Imagine if a subclass is instantied and we are going to manipulate a protected variable that was not initialized with values that are expected. Bugs, errors, or vulnerabilities can happen. Furthermore it would break the paradigm of oop: the inheritance was not going to make sense.
+ 1
thanks Tashi N 😊