Question: import java.util. * ; / / for ArrayList public class Pet { private String name; private String type; public Pet ( String n , String
import java.util.; for ArrayList
public class Pet
private String name;
private String type;
public PetString n String t
name n;
type t;
public String toString
return name is a type;
public static void mainString args
ArrayList petList new ArrayList;
petList.addnew PetSammy "hamster";
petList.addnew DogFido;
This loop will work for all subclasses of Pet
for Pet p : petList
System.out.printlnp;
class Dog extends Pet
public DogString n
supern "dog";
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
