What Will Be The Output Of The Following Java Codep Pre #909
What will be the output of the following Java code?</p> <pre><code class="language-java"> import java.io.IOException; class Derived { public void print() throws IOException { System.out.println("IOE"); } } public class Exceptions extends Derived { public void print() throws Exception { System.out.println("Exception"); } public static void main(String[] args) throws IOException { Derived obj = new Exceptions(); obj.print(); } } </code></pre>
This multiple choice question (MCQ) is related to the book/course gs gs111 OOP Object Oriented Programming Java. It can also be found in gs gs111 Polymorphism (Using Java) - Method Overriding - Quiz No.1.
What will be the output of the following Java code?
import java.io.IOException; class Derived { public void print() throws IOException { System.out.println("IOE"); } } public class Exceptions extends Derived { public void print() throws Exception { System.out.println("Exception"); } public static void main(String[] args) throws IOException { Derived obj = new Exceptions(); obj.print(); } }
Exception
IOE
Runtime error
Compilation error