My issue
no error but answer is wrong
My code
class Animal {
public void makeSound() {
System.out.println("Animal makes a sound");
}
}
class Dog extends Animal {
public void makeSound() {
System.out.println("Dog barks");
}
}
class Cat extends Animal {
public void makeSound() {
System.out.println("Cat meows");
}
}
class Codechef {
public static void main(String[] args) {
Animal animal = new Animal();
Animal animal1 = new Dog();
Animal animal2 = new Cat();
animal.makeSound(); // Output: Animal makes a sound
animal1.makeSound(); // Output: Dog barks
animal2.makeSound(); // Output: Cat meows
}
}
Learning course: Learn Advance Java
Problem Link: CodeChef: Practical coding for everyone