Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Driver {
- public static void main(String[] args) {
- Pet[] myArray = new Pet[3];
- Dog Fido = new Dog("Fido");
- Cat Toby = new Cat("Toby");
- Dog Henry = new Dog("Henry");
- myArray[0] = Fido;
- myArray[1] = Toby;
- myArray[2] = Henry;
- for (int i = 0; i < myArray.length; i++) {
- if (myArray[i] instanceof Dog) {
- System.out.println(((Dog) myArray[i]).fetch());
- }
- }
- for (int i=0; i<myArray.length; i++){
- if (myArray[i] instanceof Cat){
- System.out.println(((Pet)myArray[i]).getName());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement