Question

Consider the following code snippet (Java-like):     class Animal {         public void makeSound() {             System.out.println("Animal makes a sound");         }     }     class Dog extends Animal {         @Override         public void makeSound() {             System.out.println("Dog barks");         }     }     public class Test {         public static void main(String[] args) {             Animal myAnimal = new Dog();             myAnimal.makeSound();         }     }     What will be the output of this code?

A Animal makes a sound
B Dog barks
C Compilation Error
D Runtime Error
E Nothing, the program will not execute.
Practice Next

Hey! Ask a query