OCA Java SE 8 Mock Exam 2 - OCA Mock Question 1








Question

What will happen when you compile and run the following code?

        public class Main{ 
           private int i = 1; 
           public static void main(String argv[]){ 
              int i = 2; 
              Main s = new Main (); 
              s.someMethod(); 
           } 
           public static void someMethod(){ 
              System.out.println(i); 
           } 
         } 
  1. 1 will be printed out
  2. 2 will be printed out
  3. A compile time error will be generated
  4. An exception will be thrown




Answer



C

Note

成年女人免费毛片视频-伊人aV 影 伊人網a V在線 VYou cannot access an instance variable from a static method.