In a general sense describe when, where, and how is super keyword used in a method in java?
The super keyword in java is a reference variable that is used to refer parent class objects. The keyword “super” came into the picture with the concept of Inheritance.
Use of super with methods: It is used when we want to call parent class method. So whenever a parent and child class have same named methods then to resolve ambiguity we use super keyword. This code snippet helps to understand the said usage of super keyword.
Understanding with the help of Java program:
In the below example, it can be seen that if we only call method message() then, the current class message() is invoked but with the use of super keyword, message() of superclass could also be invoked.
Important point:
JAVA Code Snapshot:
Output Snapshot:
Get Answers For Free
Most questions answered within 1 hours.