javatutelearn.com

Easy Learning


Home

Search Javatutelearn.com :



Java Access Specifier

  1. Java protects access of variables and methods of the class using various protection mechanism.
  2. Protecting access of variables and methods is also called visibility of variables and methods.
  3. There are three types of visibility which are (i) at class level (ii) at package level (iii) at subclass level
  4. There are three types of access specifiers: (i) private (ii) public (iii) protected

Following is description for access specifiers:
  1. Private access specifier:
    • It uses the keyword ' private . '
    • Members using private access can not be accessed by outside the class .
    • Private members can not be accessed by main() function and by other classes.
    • Private members can be accessed by only members of the same class.
  2. Public access specifier:
    • It uses the keyword ' public '.
    • Members using public access can be accessed by outside the class.
    • Public members can be accessed by main() function and by other classes.
    • Public members can be accessed by anywhere.
  3. Default access:
    • If no access specifies keyword is mentioned then it is called default access .
    • Members using default access can be accessed within the package only.
    • Any class outside the package can not access any members which have default access.



© Copyright 2016-2024 by javatutelearn.com. All Rights Reserved.