Answer:
public void printAll(){ // member function petAll()
super.printAll(); // calls printAll() method of the superclass (base class) AnimalData using super keyword
System.out.print(", ID: " + idNum);} // prints the ID stored in the idNum data member of the PetData class
Explanation:
Here is the complete PetData class:
public class PetData extends AnimalData { //
private int idNum;
public void setID(int petID) {
idNum = petID; }
// FIXME: Add printAll() member function
/* Your solution goes here */
public void printAll(){
super.printAll();
System.out.print(", ID: " + idNum);} }
PetData class is a subclass which is inherited from the base class AnimalData.
This class has a private data member which is the variable idNum which is used to store the ID value.
It has a member function setID with parameter petID which is the idNum. This method basically acts as a mutator and sets the user ID.
This class has another method printAll() that uses super keyword to access the method printAll() of the base class which is AnimalData
super basically refers to the base class objects.
Here the super keyword is used with the method name of subclass PetData in order to eliminate the confusion between the method printAll() of AnimalData and PetData since both have the same method name.
In the main() method the use is prompted to enter values for userName, UserAge and UserID. Lets say user enters Fluffy as user name, 5 as user age and 4444 as userID. Then the statement userPet.printAll(); calls printAll() method of PetData class as userPet is the object of PetData class.
When this method is called, this method calls printAll() of AnimalData class which prints the Name and Age and printAll() of PetData class prints the ID. Hence the program gives the following output:
Name: Fluffy, Age: 5, ID: 4444