- Now we are assigning the reference
ref by the objects (A , B , or C ) one-by-one, and use that reference to invoke m1 .
The version of m1 executed is determined by the type of object being referred to at the time of the call.
ref = a;
// ref refers to an A object.
ref.m1( );
// Calling A's version of m1( )
ref = b;
// Now ref refers to a B object.
ref.m1( );
// Calling B's version of m1( )
ref = c;
// Now ref refers to a C object.
ref.m1( );
// Calling C's version of m1( )
|
|
|