SCJP Module-4 Question-19

The program given checks tests your knowledge for method overriding in core Java.

 
 

Share on Google+Share on Google+

SCJP Module-4 Question-19

Ads

The program given checks tests your knowledge for method overriding in core Java.

Given below the sample code :

import java.io.IOException;

class Example7 {
public float Twin(float x, float y)
throws IOException {
return 0;
}
}

class SubExample7 extends Example7 {
float Twin(float x, float y) {
return 0;
}
}

How can we correct above code ?

1. no need for correction.

2. By changing the method's argument name

3. By removing overridden method 's access specifier(i.e public).

4. By adding access specifier 'public'  to the overriding method.

Answer :

(3) & (4).

Explanation :

The overriding method must not limit access more than the overridden method i.e. the 'Twin' method in "Subexample7" doesn't have "public" access specifier.

Advertisements

Posted on: July 10, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles