Share on Google+Share on Google+

SCJP Module-6 Question-29

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*;" at line 1.




Overridden method has not "throws IOException"



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

Share this Tutorial 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.


Advertisement null