java-questions-4
1 Which one of the following represents legal flow control statements? a. break; b. break(); c. continue(inner); d. exit(); 2. Predict the output from below java program.
1 2 3 4 5 6 7 8 9 10 11 |
// public class Test { public static void main(String[] args) { try{ throw 10; }catch(int e){ System.out.println("Got the exception " + e); } } } |
Options: A. Got the exception 10 B. Go the exception 0 C. Compile time error D. Run-time error 3. Output of below java program.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
// public class Test { public static void main(String[] args) { try{ int a[] = {1,2,3,4}; for(int i=1;i<=4;i++){ System.out.println("a["+i+"]=" + a[i] + "\n"); } }catch(Exception e){ System.out.println("error: "+e); }catch(ArrayIndexOutOfBoundsException e){ System.out.println("ArrayIndexOutOfBoundsException"); } } } |