Which of the following methods can be legally inserted in place of the comment //Method Here?
class Base
{
public void amethod( int i )
{
}
}
public class Scope extends Base
{
public static void main( String argv[] )
{
//Method Here
}
}
1. void amethod( int i ) throws Exception()
2. void amethod( long i ) throws Exception()
3. void amethod( long i ){}
4. public void amethod( int i ) throws Exception
I chose answer #4 since "public" is less or equals to restrictive (in this case, equal to ) to the method that is being overriden, since the others would have a "default/package" modifier. Supposedly, the answer is #2 and #3. Can someone please explain why #2 and #3 would be correct?
SCJP 1.4
I wanted to point out that, as written, the answer is "none of the above," because the comment is inside the main() method, and you can't define "nested methods" in Java.
SCJP 1.4
Consider Paul's rocket mass heater. |