문제

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 ?

도움이 되었습니까?

해결책 3

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

다른 팁

The access modifiers specify the visibility of one class' fields for other classes. Since local variables (those declared inside methods) are never exposed, it doesn't make sense to set a certain access for them. Actually it's a compilation error, if you try it.

No it is not possible. As there are no use of it so it is restricted.

Local veriable's scope are restricted with in body so there would be no use of modying there access.

You can't use private, protected, public modifiers inside a method. Final output is compilation error.

You cannot set visibility scopes (private,...) to local variables. because The Local variables scope is already well defined : within the scope of the method it lives in.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top