Java OCA OCP Practice Question 2710

Question

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

public class Main{
   private int i = 35;
   public static void main(String argv[]){
      int i = 45;
      Main s = new Main ();
      s.someMethod();//from   w  w  w.  j av  a 2  s. c  o m
   }
   public static void someMethod(){
      System.out.println(i);
   }
 }
  • a. 35 will be printed out
  • b. 45 will be printed out
  • c. A compile time error will be generated
  • d. An exception will be thrown


c

Note

You cannot access an instance variable from a static method.




PreviousNext

Related