Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Animal {
- public abstract class bark();
- }
- class Tiger extends Animal {
- public class bark() {
- }
- }
- class Lion extends Animal {
- public class bark() {
- }
- }
- public class Bouncer {
- public void barkAnimal(Animal animal) {
- if (animal instanceof Tiger) {
- System.out.println("어흥");
- } else if (animal instanceof Lion) {
- System.out.println("으르렁");
- }
- }
- public static void main(String[] args) {
- Tiger tiger = new Tiger();
- Lion lion = new Lion();
- Bouncer bouncer= new Bouncer();
- bouncer.barkAnimal(tiger);
- bouncer.barkAnimal(lion);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement