SCJP Module-4 Question-19


 

SCJP Module-4 Question-19

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

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.

Ads