Home Tutorial Java Scjp Part6 SCJP Module-6 Question-29

 
 

SCJP Module-6 Question-29
Posted on: July 15, 2010 at 12:00 AM
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"

Related Tags for SCJP Module-6 Question-29:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.