Share on Google+Share on Google+

SCJP Module-6 Question-28

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{
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




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