«

»

May
18

public, private, and protected in Java

They are the three keywords used to define the scope of a class or method or a variable in Java. They are called access modifiers. In fact, they are four, the fourth one is «nothing» (empty, no modifier) and it is different to public.

  • public : class or method or variable using this modifier can be used by any object.
  • «nothing» : class or method or variable without modifier can be used by any class in the same package.
  • protected : class or method or variable using this modifier can be used only by the sub classes and classes in the same package.
  • private : class or method or variable using this modifier can be used only in the class where they are defined.

In general, any class or method or variable is accessible in the class where it is defined.

 

See also :

Share it with your freinds on Facebook Tweet it to your freinds on Twitter Myspace Friendfeed Technorati del.icio.us Digg Google Yahoo Buzz StumbleUpon

2 comments

No ping yet

  1. Digital SLR Reviews says:

    I won’t be able to thank you fully for the articles on your web-site. I know you’d put a lot of time and energy into all of them and hope you know how much I appreciate it. I hope I could do the same for someone else sometime.
    Samsung Camera Reviews

    1. jalal mjadli says:

      10x :)

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

WP SlimStat