SCJP Module-6 Question-29


 

SCJP Module-6 Question-29

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

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

Given below the sample code :

1   class A1{
2   public void process() { System.out.print("Inside A1 "); }}
3   class B extends A1{
4   public void process() throws IOException{
5   super.process();
6   System.out.print("Inside B ");
7   throw new IOException();
8   }
9   public static void main(String[] args){
10 try { new B().process(); }
11 catch (IOException e) { System.out.println("Exception is caught "); }}}

How can we correct the above code?

1.By adding "throws IOException" at line 2.

2. By removing "throws IOException" at line 2.

3.No need of correction.

4.By adding "import java.io.*;" at line 1.

Answer

(1)&(4)

Explanation

Overridden method has not "throws IOException"

Ads