• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Difference between Access Modifiers

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pl tell me the difference between Access Modifiers i.g private, protected,friendly and public how we can use them in packages?.
Thankx
 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hejsan!
private: a private member can only be reached from within the class it is declared in.
friendly/default: a member with no access modifier can be reached from all classes that are in the same package/folder.
protected: same as friendly/default and, in addition, the member can be reached from any subclass in any package/folder.
public: the member can be reached from any class anywhere.

Hope this helps!
//Kaspar
 
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And just a note, friendly is a Cism and is not a keyword used in Java. From what I understand, friendly and default/package access are similar but not completely identical.
Jason
 
reply
    Bookmark Topic Watch Topic
  • New Topic