Answer:
public void printAll(){ // member function petAll()
super.printAll(); // invokes printAll() method from the superclass (base class) AnimalData using the super keyword
System.out.print(", ID: " + idNum);} // displays the ID saved in the idNum field of the PetData class
Explanation:
This is the full PetData class:
public class PetData extends AnimalData { //
private int idNum;
public void setID(int petID) {
idNum = petID; }
// FIXME: Implement printAll() member method
/* Your solution goes here */
public void printAll(){
super.printAll();
System.out.print(", ID: " + idNum);} }
The PetData class is a subclass that inherits from the base class AnimalData.
This class contains a private field, idNum, which is designated for storing the ID value.
It includes a method setID which takes petID as a parameter that corresponds to idNum. Essentially, this acts as a mutator to set the user ID.
Additionally, there is a printAll() method that makes use of the super keyword to call the printAll() method from the base class, AnimalData.
Using super refers to objects of the base class.
Here, the super keyword is utilized with the method name from the subclass PetData to avoid confusion, as both AnimalData and PetData have a method named printAll().
During the main() method, users will enter values for userName, UserAge, and UserID. For example, if the user inputs Fluffy as the name, 5 as the age, and 4444 as the userID. Then, calling userPet.printAll(); will execute the printAll() method from the PetData class since userPet is an instance of PetData.
When this method executes, it will call the printAll() of AnimalData class which outputs the Name and Age, while printAll() of PetData prints the ID. Consequently, the resulting output will be:
Name: Fluffy, Age: 5, ID: 4444