Choose three from the followings:
A. private void bar(int x){}
B. public void bar(int x){}
C. public int bar(String x){return 1;}
D. public Alpha bar(int x){}
E. public void bar(int x, int y){}
F. public int bar(int x){return x;}
The answer is BCE
My question is that is that true that because class Beta subclasses Alpha, Beta can either override or overload the methods that Alpha has? Why do D and F cannot fit into that block? Thanks.
This message was edited 1 time. Last update was at by Shifong Chang
Always speak up for stupid questions.
Jim Hoglund
Ranch Hand
Joined: Jan 09, 2008
Posts: 525
posted
0
You may want to check out the method signatures . . . Jim ... ...
BEE MBA PMP SCJP-6
Afzal Rehman
Ranch Hand
Joined: Dec 16, 2009
Posts: 35
posted
0
Hi Michelle,
it's violating the rules of overriding , E is returning Alpha and superclass has void ,
and F is return int and superclass has void.
You need to keep on eye whenever you do override let say..
Must have the same argument List.
Must have the same return type . bu t in java 5 return type can be subclass this
is known as covariant return.
Must not have more restrictive modifier.
May have less less rectrivtive modifier.
etc. checkout..
but in this case void so you cann't return anything..
let us suppose that if there is any method in base class like
then you can write this in your child class this
here Beta is covariant type of Alpha
vinit
It doesn't matter if you win by an inch or a mile; winning's winning.