It is not mandatory to explicitly call the parent constructor. The super keyword in Java is used in subclasses to access superclass members (attributes, constructors and methods). In Java, we can use the super keyword within a child class constructor to invoke the super-class constructor. In this way, it first executes the parent class constructor, and then the child class constructor. We use it to call the constructor of the base class. This section will consider some examples to explain how to use the super keyword in Java:Įxample: how to use the super keyword to call the constructor of the parent class? super() in Java is always used by the user when he wishes to make constructor calls. Practical implementation of Super keyword in Java It is used to call superclass methods, and to access the superclass constructor.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |