Java - Polymorphism
a reference variable : a reference variable
- the only possible way to access an object is through _________
virtual methods
- virtual method invocation -An overridden method is invoked at run time, no matter what data type the reference is that was used in the source code at compile time.
a reference variable : refer
A reference variable can _____ to any object of its declared type or any subtype of its declared type.
a reference variable : a class or interface type
A reference variable can be declared as _______.
a reference variable : only one type
A reference variable can be of __________. Once declared, the type of a reference variable cannot be changed.
a reference variable : reassigned
The reference variable can be ________ to other objects provided that it is not declared final.
a reference variable : The type of the reference variable
________ would determine the methods that it can invoke on the object.
Polymorphism
_____________ is the ability of an object to take on many forms.
Java object that can pass more than one IS-A test
is considered to be polymorphic
most common use of polymorphism in OOP
occurs when a parent class reference is used to refer to a child class object.
Polymorphism Example
public interface Vegetarian{} public class Animal{} public class Deer extends Animal implements Vegetarian{} Now, the Deer class is considered to be polymorphic since this has multiple inheritance. Following are true for the above examples − A Deer IS-A Animal A Deer IS-A Vegetarian A Deer IS-A Deer A Deer IS-A Object When we apply the reference variable facts to a Deer object reference, the following declarations are legal -- Deer d = new Deer(); Animal a = d; Vegetarian v = d; Object o = d; All the reference variables d, a, v, o refer to the same Deer object in the heap.
