525,716 views
17 votes
17 votes
10.11 LAB: Pet information (derived classes) The base class Pet has private data members petName, and petAge. The derived class Dog extends the Pet class and includes a private data member for dogBreed. Complete main() to: create a generic pet and print information using PrintInfo(). create a Dog pet, use PrintInfo() to print information, and add a statement to print the dog's breed using the GetBreed() function.

User Eadz
by
3.0k points

1 Answer

22 votes
22 votes

Answer:

Answered below.

Step-by-step explanation:

//Program in Java

Class Test{

public static void main (String[] args){

//create a pet object

Pet pet = new Pet();

//call pet object's printInfo method

pet.printInfo();

//create a new Dog object

Dog dog = new Dog();

//dog can access the printInfo method of the Pet class because it derives from it

dog.printInfo();

//dog can also call it's private method.

dog.getBreed();

}

}

User Ryan Reich
by
3.2k points