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.
(4)
Above code will give compile error because override method can't throws any exception ,which was not thrown by overridden method.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.