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

Slides:



Advertisements
Similar presentations
Why not just use Arrays? Java ArrayLists.
Advertisements

Sentence Fragments. Writing Do Now: Correct the following M.U.G. shot: Correct the following M.U.G. shot: Running to the store soo fast like lightning.
GridWorld Case Study The Classes A Summary by Jim Mims.
GridWorld Case Study Part 2 Bug Variations A Summary by Jim Mims.
GridWorld Case Study Part 4 Classes that Extend the Critter Interface A Summary by Jim Mims.
GridWorld Case Study Part 5 Grid Data Structures Not Tested on A Exam A Summary by Jim Mims.
© A+ Computer Science - GridWorld © A+ Computer Science -
Critters A Study in Design Patterns. Design Patterns  Not specific algorithms or data structures  A general reusable solution to a common problem.
Inheritance and Polymorphism Dr. M.M. van Baal Verdugo Hills High.
Inheritance and object compatibility Object type compatibility An instance of a subclass can be used instead of an instance of the superclass, but not.
Improving structure with inheritance
Topic 6 Generic Data Structures "Get your data structures correct first, and the rest of the program will write itself." - David Jones.
Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
Pulling out a common superclass Barb Ericson Georgia Tech.
Chapter 13 – Aggregation, Composition, and Inheritance
GridWorld Case Study1 Barbara Ericson Georgia Tech Jan 2008.
Shakespeare. 1.  How old was Shakespeare when he died?
Algebra 1A Vocabulary 1-2 Part 2
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
Object-Oriented Programming (OOP). Implementing an OOD in Java Each class is stored in a separate file. All files must be stored in the same package.
Parameters… Classes Cont Mrs. C. Furman October 13, 2008.
Java course. Assignment #2, due: Feb. 27, (20) (a) Tell the difference between the abstract class and the interface. (b) Tell the difference between.
GridWorld Case Study Barbara Ericson March 24, 2007.
Best seller Your solution to the store’s sale signs!!
Generic Data Structures "Get your data structures correct first, and the rest of the program will write itself." - David Jones EE 422CGenerics 1.
MCQ Which is the correct syntax for placing the string "boat" into an ArrayList name recVehicles in position 3 (index 2) for the first time? a)recVehicles.set(3,
The GridWorld Case Study Program Section 1 - Overview of the Class Hierarchies Section 2 - The Actor Class Section 3 - The Rock and Flower Classes Section.
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
SEG2105 FINAL REVIEW December 2015
Typecasting References Computer Science 3 Gerb Reference: Objective: Understand how to use the Object class in Java in the context of ArrayLists.
Slide 0. Inheritance and Polymorphism Mr. Landa South East High.
Chapter 8: Part 3 Collections and Two-dimensional arrays.
GridWorld Case Study The case study is a program that simulates actions and interactions of objects in a two- dimensional grid. During a single step of.
 Static  Example for Static Field  Example for Static Method  Math class methods  Casting  Scope of Declaration  Method Overloading  Constructor.
I have decided to follow Jesus. No turning back, no turning back.
JAVA CLASSES, METHODS AND VARIABLES.  Defined Noun: A set or category of things having some property or attribute in common and differentiated from others.
© A+ Computer Science - Visit us at Full Curriculum Solutions M/C Review Question Banks.
GridWorld.
ARRAYLIST AND VECTOR.
Arrays and the ArrayList Class The ArrayList Class
GridWorld Part 4 Meet the Critters.
Agenda About Quiz ChameleonCritter class CrabCritter class homework.
Barbara Ericson Georgia Tech Jan 2008
Continuing Chapter 11 Inheritance and Polymorphism
Topic 6 Generic Data Structures
AP "Case Studies" A big program for AP students to understand
PRG 421 Education for Service-- snaptutorial.com.
PRG 421 Education for Service-- snaptutorial.com.
PRG 421Competitive Success/tutorialrank.com
آشنايی با اصول و پايه های يک آزمايش
Unit 7. Day 7..
© A+ Computer Science - GridWorld © A+ Computer Science -
Inheritance and Polymorphism
Inheritance and Polymorphism
Object-Oriented Programming Paradigm
Word Formation.
I Have Decided.
Economics and Business Management Unit 7 Word Formation
Which of the following graphs corresponds to the inequality {image} ?
GridWorld Part 4 Meet the Critters.
STORE MANAGER RESPONSIBILITIES.
Programming II (CS300) Chapter 02: Using Objects Java ArrayList Class
1.4 ทบทวน JAVA OO Programming Concepts Declaring and Creating Objects
GridWorld Case Study.
Scratch Programming Lesson 7 Debugging.
© A+ Computer Science - GridWorld © A+ Computer Science -
© A+ Computer Science - GridWorld © A+ Computer Science -
Types of Errors And Error Analysis.
Presentation transcript:

Polymorphism

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.

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!!!