Download presentation
Presentation is loading. Please wait.
Published byGwen French Modified over 9 years ago
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!!!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.