The super Keyword in Java


super is used to call superclass methods and constructors.

Source Code

class Animal {
    String name;
    Animal(String name) {
        this.name = name;
    }
}
class Dog extends Animal {
    Dog() {
        super("Dog"); // Calls the superclass (Animal) constructor
    }
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments