✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.
What is the output of the following program?
class Animal { protected String name;
protected void display() { System.out.println("I am an animal."); }}
class Dog extends Animal { protected void display() { System.out.println("I am a Dog"); } public void getInfo() { System.out.println("My name is " + name); }}
class Main { public static void main(String[] args) {
// create an object of the subclass Dog labrador = new Dog();
// access protected field and method // using the object of subclass labrador.name = "Rocky"; labrador.display();
labrador.getInfo(); }}