Difference Between This And Super Keyword In Java
Understanding the Difference between 'this' and 'super' Keywords in Java
Difference Between This And Super Keyword In Java
In Java, the “this” keyword is a reference to the current object, while the “super” keyword is a reference to the immediate parent class of the current object. When used inside a method or constructor, “this” refers to the current instance of the class, allowing access to instance variables and methods. On the other hand, “super” is used to access members of the superclass that are hidden by members of the subclass. By using “super”, you can call constructors, methods, and instance variables of the superclass from the subclass.
To Download Our Brochure: https://www.justacademy.co/download-brochure-for-free
Message us for more information: +91 9987184296
1 - The ‘this’ keyword in Java refers to the current instance of a class, whereas the ‘super’ keyword refers to the immediate parent class of the current class.
2) ‘this’ is used to refer to the current object's instance variables or methods, while ‘super’ is used to access the parent class's members.
3) ‘this’ can be used to invoke current class constructors, while ‘super’ is used to invoke parent class constructors.
4) ‘this’ is primarily used for avoiding naming conflicts between instance variables and parameters, while ‘super’ is used to access overridden methods or variables in the parent class.
5) Using ‘this’ is optional in Java, while ‘super’ is automatically included in a subclass constructor if it is not explicitly declared.
6) Accessing methods or variables with ‘this’ will always refer to the current class, whereas using ‘super’ allows access to members of the parent class.
7) ‘this()’ can be used as a constructor call in the current class, while ‘super()’ is used to call a constructor in the parent class.
8) ‘this’ and ‘super’ keywords are fundamental to Java inheritance and are essential for understanding and building object oriented programs efficiently.
Browse our course links : https://www.justacademy.co/all-courses
To Join our FREE DEMO Session: Click Here
Contact Us for more info:
- Message us on Whatsapp: +91 9987184296
- Email id: info@justacademy.co
Javascript Interview Questions For 5 Years Experience
Interview Questions On Html Css Javascript