13.Create a program, showing an example of method overriding
💡Code:
class Animal { void makeSound() { System.out.println("The animal makes a sound"); } } class Dog extends Animal { @Override void makeSound() { System.out.println("The dog barks"); } } class Cat extends Animal { @Override void makeSound() { System.out.println("The cat meows"); } } class inheritance13_7024 { public static void main(String[] args) { Animal animal = new Animal(); animal.makeSound(); Dog dog = new Dog(); dog.makeSound(); Cat cat = new Cat(); cat.makeSound(); } }
📸Output :
