Java OCA OCP Practice Question 2602

Question

Consider the following program and predict the output:

class  Main {/*from w  w w.j  ava2s  .  co m*/
        int a = 0;
        public static void print(int a) {
                this.a = a;
                System.out.println("a = " + this.a);
        }
        public static void main(String[] args) {
                Main obj = new Main();
                obj.print(10);
        }
}
  • a) The program will report a compiler error.
  • b) The program will generate a runtime exception.
  • c) The program will print the following: a = 0.
  • d) The program will print the following: a = 10.


a)

Note

The keyword this cannot be used in a static method, so the program will not compile.




PreviousNext

Related