Your are given the following classes: public abstract class Animal{ public abstract void talk(); } public class Dog extends Animal{ public void talk(){ System.out.println ("Woof"); } } public class...


Your are given the following classes:<br>public abstract class Animal{<br>public abstract void talk();<br>}<br>public class Dog extends Animal{<br>public void talk(){<br>System.out.println (

Extracted text: Your are given the following classes: public abstract class Animal{ public abstract void talk(); } public class Dog extends Animal{ public void talk(){ System.out.println ("Woof"); } } public class Cat extends Animal{ public void talk(){ System.out.println ("Meow"); } } You must modify the class Owner provided below, so that objects of this class can hold objects of both classes Dog and Cat in their array. Note you must also modify the methods add and getPet accordingly. Answer: (penalty regime: 0 %) Reset answer public class Owner{ private Dog[] dogs; private int numDogs=0; 3 4 public Owner(){ dogs = new Dog[5]; } 6. 7 8 public void add(Dog a){ dogs[numDogs] = a; numDogs++; } 9 10 11 12 13 public Dog getPet (int index){ return dogs[index]; } 14 15 16 17 }

Jun 05, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions ยป

Submit New Assignment

Copy and Paste Your Assignment Here