Рет қаралды 164,173
Whenever you create the object of subclass, then it calls the constructor of subclass as well as of parent class.
-When we object of subclass by specifying the parameter, it will call specified constructor of subclass but it will call the default constructor of superclass.
Why the object of subclass always call the default constructor of super class?
- Every constructor in subclass will have a by default method called as "super".
- Super method is by default given by the compiler even if you do not mention it.
Super keyword:-
- The super keyword in Java is a reference variable that is used to refer parent class objects.
- super can be used to call parent class’ variables and methods.
Super method:-
- The super keyword can also be used to access the parent class constructor by adding ‘()’ after it like super().
- Super() method will directly call the constructor of superclass.
- By default, complier puts the super method without parameters.
- If you will pass parameters to super method, then it will call the parameterized constructor of the super class.
- ‘super()’ can call both parametric as well as non-parametric constructors depending upon the situation.
In this video we will see:
- How to call constructors of both subclass and superclass?
- Why object of subclass always call the default constructor of super class?
- Super keyword
- Super() method
Instagram : / navinreddyofficial
Linkedin : / navinreddy20
Discord : / discord
More Learning :
Java - bit.ly/3xleOA2
Python :- bit.ly/3H0DYHx
Django :- bit.ly/3awMaD8
Spring Boot :- bit.ly/3aucCgB
Spring Framework :- bit.ly/3GRfxwe
Servlet & JSP :- bit.ly/3mh5CGz
Hibernate Tutorial :- bit.ly/3NWAKah
Rest API | Web Service Tutorial :- bit.ly/38RJCiy
Git :- bit.ly/3NUHB3V
JavaScript :- bit.ly/3mkcFys
Kotlin :- bit.ly/3GR2DOG
Donation:
PayPal Id : navinreddy20
Patreon : navinreddy20
www.telusko.com...