What does ‘super’ mean in Java?
In Java, super is a keyword used to refer to the parent class object or parent class constructor. It can be used to access the methods, properties, and constructors of the parent class.
- Using super to call the parent class’s method: The super keyword allows for calling the parent class’s method within the subclass. This is particularly useful when the subclass overrides the parent class’s method, to utilize super to call the parent class’s method and then add specific implementations in the subclass.
- Using super to access parent class properties: By using the super keyword, it is possible to access parent class instance variables in a subclass. When there are instance variables with the same name in both the subclass and parent class, using super clearly specifies that the parent class instance variable is being accessed.
- Call the parent class constructor using super: In the subclass constructor, you can use the super keyword to call the parent class constructor. This ensures that when creating a subclass object, the parent class constructor will also be executed.
In conclusion, the keyword “super” in Java represents a parent class object or constructor, and can be used to access the methods, attributes, and constructors of the parent class.