Which of the following is true about the ‘super’ keyword in Java?

Java MCQ: Which of the following is true about the ‘super’ keyword in Java?

a) ‘super’ is used to refer to the immediate parent class object
b) ‘super’ can be used to call parent class methods
c) ‘super’ can be used to call parent class constructors
d) All of the above

Answer:

d) All of the above

Explanation:

In Java, the super keyword is used to refer to the immediate parent class object. It is commonly used to call the parent class’s methods and constructors. When a subclass needs to access a method or a field from its superclass that has been overridden, it can use super to do so.

The super() call is also used to invoke the parent class’s constructor from the subclass’s constructor. This is particularly useful when the parent class has a parameterized constructor that needs to be called before initializing the subclass’s fields.

Understanding how and when to use super is essential for managing inheritance in Java and ensuring that the parent class’s behavior is appropriately leveraged in subclasses.

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