Java OCA OCP Practice Question 1964

Question

What will be the result of compiling and running the following program?.

public class Main {
 static final Integer i1 = 1;
 final Integer i2 = 2;
 Integer i3 = 3;/*from   w ww  . java  2s .c o  m*/

 public static void main(String[] args) {
   final Integer i4 = 4;
   Integer i5 = 5;

   class Inner {
     final Integer i6 = 6;
     Integer i7 = 7;

     Inner () {
       System.out.print(i6 + i7);
     }
   }
 }
}

Select the one correct answer.

  • (a) The program will fail to compile.
  • (b) The program will compile but throw an exception when run.
  • (c) The program will compile and print 67, when run.
  • (d) The program will compile and print 13, when run.
  • (e) The program will compile but will not print anything, when run.


(e)

Note

No statement is executed in the main() method that will print anything.

The print statement in the constructor of the Inner class will only be executed if an object of the Inner class is created in the main() method.




PreviousNext

Related