Method Overriding in Java


Method overriding allows a subclass to provide a specific implementation of a method already provided by its superclass.

Source Code

class Animal {
    void speak() {
        System.out.println("The animal speaks");
    }
}
class Dog extends Animal {
    @Override
    void speak() {
        System.out.println("The dog barks");
    }
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments