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


Share on Google+Share on Google+
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.




Overridden method has not "throws IOException"


Related Tags for SCJP Module-6 Question-29:

Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: July 15, 2010

Recommend the tutorial

Advertisements Advertisements