The statement y.get2( ); will

The statement y.get2( ); will

a)       return 5
b)       return 6
c)       return 3
d)       return 0
e)       cause a run-time error


Consider a class that stores 2 int values.  These values can be assigned int values with the messages set1(x) and set2(x) where x is an int, and these values can be accessed through get1( ) and get2( ).  Assume that y and z are two objects of this class.  The following instructions are executed:
y.set1(5);
y.set2(6);
z.set1(3);
z.set2(y.get1( ));
y = z;

Answer:  a.

Explanation:  The statement y = z; causes y and z to be aliases where y.get2( ); returns the same value as z.get2( );.  Since z.set2(y.get1( )); was performed previously, z and y's second value is 5.


Enhancing Classes

Learn More Multiple Choice Question :