The moose likes Beginning Java and the fly likes Help needed with access specifiers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help needed with access specifiers" Watch "Help needed with access specifiers" New topic

Help needed with access specifiers

brahmjyot singh

Joined: Jan 04, 2010
Posts: 1
This is probably more of a design question.

How would we use java access specifers in designing a real world class.Java textbooks tend to give a rather rigid definition
In short i am looking for a REAL example.
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 987

It depends on a scenario,

usually i prefer to use private for all class instance variables,
protected for methods (mostly not variables) that can be accessed to same package
public for methods that can be accessed every where

My Website: [] Cool your mind:[] My Sally:[]
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 45360
And welcome to JavaRanch
I agree. Here's the link:
subject: Help needed with access specifiers
It's not a secret anymore!