Java MCQ: Which of the following is true about the ‘super’ keyword in Java?
Answer:
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