forked from angiejones/java-programming
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathZoo.java
More file actions
32 lines (24 loc) · 647 Bytes
/
Copy pathZoo.java
File metadata and controls
32 lines (24 loc) · 647 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package chapter10;
public class Zoo {
public static void main(String[] args){
Dog rocky = new Dog();
rocky.fetch();
rocky.makeSound();
feed(rocky);
Animal sasha = new Dog();
sasha.makeSound();
feed(sasha);
sasha = new Cat();
sasha.makeSound();
((Cat) sasha).scratch();
feed(sasha);
}
public static void feed(Animal animal){
if(animal instanceof Dog){
System.out.println("here's your dog food");
}
else if(animal instanceof Cat){
System.out.println("here's your cat food");
}
}
}