Java OCA OCP Practice Question 432

Question

Which of the statements regarding the following code are correct?

public class Main {
   static int a;
   int b;//from   w  ww.j a  va  2 s  .co m

   public Main() {
      int c;
      c = a;
      a++;
      b += c;
   }

   public static void main(String args[]) {
      new Main();
   }
}

Select 1 option

  • A. The code will fail to compile because the constructor is trying to access static members.
  • B. The code will fail to compile because the constructor is trying to use static member variable a before it has been initialized.
  • C. The code will fail to compile because the constructor is trying to use member variable b before it has been initialized.
  • D. The code will fail to compile because the constructor is trying to use local variable c before it has been initialized.
  • E. The code will compile and run without any problem.


Correct Option is  : E

Note

All the instance or static variables are given a default values if not explicitly initialized.

All numeric variable are given a value of zero or equivalent to zero (i.e. 0.0 for double or float ).

booleans are initialized to false and objects references are initialized to null.




PreviousNext

Related