READING CHAPTER 13 SECTION 2 "Using Classes Effectively with Polymorphism" - advantage of inheritance - can put multiple different types in an array - use the common parent class as the array type - polymorphism - allow a single variable to refer to objects from different classes - declare variable with a particular type - can assign to that variable - any object of that type - any object that has that type as an ancestor - cannot assign - superclass - *sibling classes* - classes that share a common ancestor class - can call a method using a polymorphic variable name - at runtime, computer sees which class actually is - calls that implementation of the method - polymorhpic method may call methods implemented in different classes depending on the runtime type of its object - benefits of polymorphism - makes possible smooth and easy extension and modification of a program - don't have to change existing code - difficult to change existing code, because to ensure it works correctly, must understand completely - occasionally need to determine the class of a referenced object - use instanceof operator - left operand is an object - right operand is a class name - returns a boolean: whether that object is an instance of that class Quick Check 1. Cannot do: Truck t = new Vehicle(); // because Vehicle is an ancestor of Truck, not a descendent Motorcycle m = new Vehicle(); // analogous to above Motorcycle m2 = new Truck(); // Motorcycle and Truck are siblings; Truck isn't a descendent of Motorcycle 2. We can use the instanceof operator to determine whether an object is an instance of a particular class.