Posts

Showing posts with the label Method Overriding

Method Overriding

Method Overriding :    Explanation:            Method overriding allows a subclass to provide a specific implementation for a method defined in its superclass. Example: c lass Animal {     void makeSound() {         System. out .println( "Animal makes a sound." );     } }   class Cat extends Animal {     @Override     void makeSound() {         System. out .println( "Cat meows." );     } }   public class Main {     public static void main(String[] args ) {         Animal myCat = new Cat();         myCat .makeSound(); // Output: Cat meows .     } }