Write a Java program to demonstrate method overriding with a subclass that overrides a method from its superclass
The code defines a simple hierarchy of classes in Java, and it demonstrates method overriding, which is a fundamental concept in object-oriented programming. Here's an explanation of the code:
class Animal { void makeSound() { System.out.println("Animal makes a sound"); } } class Dog extends Animal { @Override void makeSound() { System.out.println("Dog Barks"); } } public class Main { public static void main(String[] args) { Dog dog = new Dog(); dog.makeSound(); } }
Dog Barkss
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions