Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Access Modifiers

 
 

Share on Google+Share on Google+

Access Modifiers

Advertisement
Access Modifiers : Access modifiers are used to specify the visibility and accessibility of a class, member variables and methods.

Access Modifiers

     

Access Modifiers : Access modifiers are used to specify the visibility and accessibility of a class, member variables and methods. Java provides some access modifiers like: public, private etc.. These can also be used with the member variables and methods to specify their accessibility. 

  1. public keyword specifies that the public class, the public  fields and the public methods can be accessed from anywhere.
     
  2. private: This keyword provides the accessibility only within a  class i.e. private fields and methods can be accessed only within the same class.
      
  3. protected: This modifier makes a member of the class available to all classes in the same package and all sub classes of the class. 
      
  4. default : Its not a keyword. When we don't write any access modifier then default is considered. It allows the class, fields and methods accessible within the package only.
Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: December 18, 2008

Related Tutorials

Discuss: Access Modifiers   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:2
Amruta
March 2, 2012
protected access specifier

I can explain me protected please.
Sudip
March 27, 2012
private constructor

Is it possible for accessibility of data member in subclass of private constructor??
DMCA.com