Java MCQ: What does the ‘super’ keyword do in Java?
Answer:
Explanation:
In Java, the super
keyword is used to refer to the superclass (parent class) of the current object. It can be used to access methods and constructors of the superclass that have been overridden or to call a superclass constructor.
For example, within a subclass, you can use super()
to invoke the constructor of the superclass. This is particularly useful when you need to perform the initialization defined in the superclass before adding additional initialization in the subclass.
Additionally, super
can be used to call a method from the superclass that has been overridden in the subclass, ensuring that the original behavior is preserved.
Reference links:
https://www.rameshfadatare.com/learn-java-programming/
https://www.javaguides.net/p/java-tutorial-learn-java-programming.html