SCJP Module-6 Question-28

The Sample program given below will check your knowledge of method overriding in Java.

 
 

Share on Google+Share on Google+

SCJP Module-6 Question-28

Ads

The Sample program given below will check your knowledge of method overriding in Java.

Given below the sample code :

class A1{
public void process() { System.out.print("Inside A1 "); }}
class B extends A1{
public void process() throws IOException{
super.process();
System.out.print("Inside B ");
throw new IOException();
}
public static void main(String[] args){
try { new B().process(); }
catch (IOException e) { System.out.println("Exception is caught "); }}}

What will be the output of the above code?

1.Inside A1

2.Inside A1 Inside B

3.Inside A1 Inside B Exception is caught

4.Error in compilation

Answer

(4)

Explanation

Overridden method has not "throws IOException"

Advertisements

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