DriveReady

OOP: the four pillars, overloading vs overriding · Accenture

0 answered · 0 rightBack
Question 1 of 16EasyD1 — runtime polymorphism

What is the output of the following Java program?

class Animal { void sound() { System.out.print("generic "); } }
class Dog extends Animal { void sound() { System.out.print("bark "); } }

public class Main {
    public static void main(String[] args) {
        Animal x = new Dog();
        x.sound();
        Animal y = new Animal();
        y.sound();
    }
}