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

 
 

Share on Google+Share on Google+
SCJP Module-6 Question-28
Posted on: July 15, 2010 at 12:00 AM
Advertisement
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{
super.process();
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

Answer

(4)

Explanation

Overridden method has not "throws IOException"

Advertisement

Related Tags for SCJP Module-6 Question-28:


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
 

 

 

DMCA.com