What does the ‘super’ keyword do in Java?

Java MCQ: What does the ‘super’ keyword do in Java?

a) It refers to the superclass
b) It creates a new object
c) It overrides a method
d) It finalizes an object

Answer:

a) It refers to the superclass

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

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top