logo

Crowdly

Browser

Add to Chrome

What is the output of the following program? class Animal { protected Strin...

✅ 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();

}

}

0%
0%
0%
More questions like this

Want instant access to all verified answers on moodle.medtech.tn?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!

Browser

Add to Chrome