Show Mobile Navigation

Webring

Powered by WebRing.

Scope of varibales in Java

Sachin R Kukale - 20:28
Access modifiers in Java are some reserved and the meaning of each word already defined and is fixed. These access modifiers are mainly used to define the scope of access particular program element in Java. The access modifier keywords in Java are:
ü  Private
ü  Protected
ü  Public
Following are some scope/access modifiers:
        i.            Private Scope: If you use ‘private’ keyword with class member then scope of that member will be private and such members of class can be accessed only within the class in which they are declared. Such members of one class cannot be accessed outside that class and also not in sub-class of a class where they are declared.
If a variable is defined as ‘private’ then while creating object memory will be allocated and you can access such members by using non-private members also.
      ii.            Package Scope: If you are not specifying any access modifier then scope of such members of class will be package scope i.e. such members can be accessed from any other member in the same package. Such members cannot be accessed outside the package.
    iii.            Public Scope: Members defined as ‘public’ specifies the public scope of that member which means those members can be accessed anywhere inside the package or outside the package in which it is declared.

     iv.      Protected Scope: Members defined with ‘protected’ keyword will be in protected scope. Such members can be accessed inside the class in which they are declared. Such members can be accessed outside the package in which they are declared but the class must be child to where they are declared.

0 comments:

Post a Comment