Consider the following code:
class MyClass { //from w w w .ja va 2 s.c o m public XXX m1 (int a){ return a*10/4-30; } } class MyClass2 extends MyClass { public YYY m1 (int a){ return a*10/4.0; } }
What can be substituted for XXX and YYY so that it can compile without any problems?
Select 1 option
Correct Option is : C
The overriding method is allowed to return a subclass of the return type defined in the overridden method.
If a base class's method is: public MyClass m (); then a subclass is free to override it with: public MyClass1 m (); if MyClass 1 extends MyClass.