What will be the result of compiling and running the following code?
class Base{ // w w w .j a v a2 s . c om public short getValue (){ return 1; } //1 } class Base2 extends Base{ public byte getValue (){ return 2; } //2 } public class Main{ public static void main (String [] args){ Base b = new Base2 (); System.out.println (b .getValue ()); //3 } }
Select 1 option
Correct Option is : D
In case of overriding, the return type of the overriding method must match exactly to the return type of the overridden method if the return type is a primitive.
In case of objects, the return type of the overriding method may be a subclass of the return type of the overridden method.