Presentation is loading. Please wait.

Presentation is loading. Please wait.

Polymorphism. ArrayList boxbugs; ArrayList critters; ArrayList kingCrabs; ArrayList workerants; boxbugs.get(i).act(); critters.get(i).act(); kingCrabs.get(i).act();

Similar presentations


Presentation on theme: "Polymorphism. ArrayList boxbugs; ArrayList critters; ArrayList kingCrabs; ArrayList workerants; boxbugs.get(i).act(); critters.get(i).act(); kingCrabs.get(i).act();"— Presentation transcript:

1 Polymorphism

2 ArrayList boxbugs; ArrayList critters; ArrayList kingCrabs; ArrayList workerants; boxbugs.get(i).act(); critters.get(i).act(); kingCrabs.get(i).act(); workerants.get(i).act(); ArrayList actors; actors.get(i).act(); Java correctly decides which type of actor it is and calls the corresponding act() method. All actors act differently, even though they are all being stored as plain old Actors.

3 Actor Bug BoxBug ZBug Critter RockHound Actor a = new BoxBug(4); a.act(); act(); getActors() BoxBugs act() called Actor a = new RockHound(); a.getActors(); No getActors() method!!!! ERROR!!!


Download ppt "Polymorphism. ArrayList boxbugs; ArrayList critters; ArrayList kingCrabs; ArrayList workerants; boxbugs.get(i).act(); critters.get(i).act(); kingCrabs.get(i).act();"

Similar presentations


Ads by Google