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

 
 

Share on Google+Share on Google+
SCJP Module-6 Question-14
Posted on: July 14, 2010 at 12:00 AM
Advertisement
The given program will test your understanding about the Inheritance and method overriding in Java.

Given below the sample code :

class SuperClass {
public void MyMethod() {
System.out.print("SuperClass,");
}
}

class SubClass extends SuperClass {
public void MyMethod() throws IOException {
super.MyMethod();
System.out.print("SubClass,");
throw new IOException();
}

public static void main(String[] args) {
try {
new SubClass().MyMethod();
} catch (IOException e) {
System.out.println("Exception");
}
}
}

What will be the output of the following code ?

1. SuperClass

2. SubClass

3. SubClass

    SuperClass

4. Gives Compile error.

Answer :

(4)

Explanation :

Above code will give compile error because override method can't throws any exception ,which was not thrown by overridden method.

  

Advertisement

Related Tags for SCJP Module-6 Question-14:


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 14, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com