Access Specifiers in Java- Key Points

  • Encapsulation links data with the code that manipulates it. 
  • Encapsulation provides another important attribute called access control.
  • Java’s access specifiers are public, private, and protected.
  • A default access level is also defined in Java.
  • protected applies only during inheritance.
  • When a member of a class is declared as public, then that member can be accessed by any other code.
  • When a member of a class is declared as private, then that member can only be accessed by other members of its class.
  • When no access specifier is used, then by default the member of a class is public within its own package, but cannot be accessed outside of
  • its package.  
  • main( ) method in Java is declared as public because it is called by code that is outside the program—that is, by the Java run-time system.  

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s