Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What is the o/p of following program? public class Question05 { public static vo

ID: 3543332 • Letter: W

Question

What is the o/p of following program?

  public class Question05 {

   public static void main(String[] args) {
    Question05Sub myref = new Question05Sub();
     try{
      myref.test();
      }catch(IOException ioe){}
   }

   void test() throws IOException{
   System.out.println("In Question05");
   throw new IOException();
   }
}

  class Question05Sub extends Question05 {

    void test() {
     System.out.println("In Question05Sub");
    }
  }

a) In Question05
b) In Question05Sub
c) Compilation error
d) In Question05
  In Question05Sub

Explanation / Answer

Answer is c. If the parent method throws a Checked Exception then the child class overriding it can throw same exception or unchecked exception or any subclass of the Exception thrown (in this case subclass of IOException)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote