SCJP Module-4 Question-7

The program given below tests your understanding of method overriding in Java and help you for preparation of SCJP exam.

 
 

Share on Google+Share on Google+

SCJP Module-4 Question-7

Ads

The program given below tests your understanding of method overriding in Java and help you for preparation of SCJP exam.

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;
}
}

Is the above code run successfully ?Choose correct options :

1.Yes ,overloading is correct.

2.Yes , overriding is correct.

3.No, overriding is incorrect.

4.Compile successfully but not run.

Answer :

(3)

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 9, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles