Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java question Consider the following three class declarations public class Anima

ID: 3825195 • Letter: J

Question

Java question

Consider the following three class declarations public class Animal { protected String name; public Animal (String name) { this, name = name; } public void print () { System, out. print In ("Animal"); } } public class Mammal extends Animal { protected boolean nocturnal; public Mammal (String name, boolean nocturnal) { super(name); this, nocturnal = nocturnal; } public void print () { System, out. print In ("Mammal") { } public class Sloth extends Mammal { public int population; public Sloth (String name, boolean nocturnal, int population) super (name, nocturnal) ; this, population = population; } public void print () { System, out. print In ("Sloth"); } Write a method (including both the method head and body) named printArray() that takes an array containing objects of type Animal, Mammal and/or Sloth. The method iterates through the Array and calls the print () method for each object.

Explanation / Answer

void printArray(Animal[] animalArray)
{
for(int i = 0;i < animalArray.length; i++)
{
animalArray[i].print();
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote