Showing posts with label java superclass subclass concept. Show all posts
Showing posts with label java superclass subclass concept. Show all posts

Wednesday, April 17, 2013

Extends KeyWord Questions

1)       class A1 extends Exception{}
       class B1 extends A1{}
       class C1 extends B1{}
       public class Test {
          static void aMethod() throws C1{ throw new C1(); }
          public static void main(String[] args){
          int x = 10;
           try { aMethod(); }
           catch(A1 e) { System.out.println("Error A");}
           catch(B1 e) { System.out.println("Error B");}
          }
       }


A)Error B
B)compilation error
c)Runtime error
d)Error A

 Ans : compilation error
Reason : Unreachable catch block for B. It is already handled by the catch block for A