Search code examples
javamethodsaccess-specifier

Explain the output of the program in java ?


In this program Is it possible to use the access specifier inside the method

class AccessTest{
int i;

   public static void main (String... str) 
  {
   int i;
   private int a = 1;
   protected int b = 1;
   public int c = 1;
   System.out.print (a+b+c);
  }

}

what is the final output can anybody explain this ?


Solution

  • Variables declared in a method are local to the method; i.e. they can't be accessed outside the method.