OOPs 1

Ques 17: Given: 
 class One {
    public One() { System.out.print(1); }
 } 
class Two extends One {
    public Two() { System.out.print(2); }
 }
 class Three extends Two {
    public Three() { System.out.print(3); }
 }
 public class Numbers{
    public static void main( String[] argv ) { new Three(); }
 }

What is the result when this code is executed?
A. 1
B. 3
C. 123
D. 321
E. The code runs with no output.
Answer: C

Exception Handling - 2

Ques 2:
Which are most typically thrown by an API developer or an application developer as opposed to being thrown by the JVM? (Choose all that apply.)
A. ClassCastException
B. IllegalStateException
C. NumberFormatException
D. IllegalArgumentException
E. ExceptionInInitializerError

Answer: 
-- B , C, and D are correct. B is typically used to report an environment problem such as trying to access a resource that’s closed. C is often thrown in API methods that attempt
to convert poorly formed String arguments to numeric values. D is often thrown in API
methods that receive poorly formed arguments. 
-- A and E are thrown by the JVM.

Exceptions Handing -1

Que 1:
class Input {
   public static void main(String[] args) {
     String s = "-";
     try {
          doMath(args[0]);
          s += "t "; // line 6
      }
      finally { System.out.println(s += "f "); }
    }
   public static void doMath(String a) {
       int y = 7 / Integer.parseInt(a);
   } 
}

And the command-line invocations:
java Input
java Input 0
Which are true? (Choose all that apply.)
A. Line 6 is executed exactly 0 times.
B. Line 6 is executed exactly 1 time.
C. Line 6 is executed exactly 2 times.
D. The finally block is executed exactly 0 times.
E. The finally block is executed exactly 1 time.
F. The finally block is executed exactly 2 times.
G. Both invocations produce the same exceptions.
H. Each invocation produces a different exception.
Answer:
-> A , F, and H are correct. Since both invocations throw exceptions, line 6 is never reached. Since both exceptions occurred within a try block, the finally block will always execute. The first invocation throws an   ArrayIndexOutOfBoundsException, and the second invocation throws an ArithmeticException for the attempt to divide by zero.
-> B, C, D, E, and G are incorrect based on the above.