SCJP Module-6 Question-28


 

SCJP Module-6 Question-28

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

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"

Ads