This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes private reference variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "private reference variable" Watch "private reference variable" New topic
Author

private reference variable

karan bhalla
Greenhorn

Joined: Jul 07, 2011
Posts: 2
what does a PRIVATE reference variable(say... private student s=new student) actually mean??? what about its scope?? help
thanks in advance

Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

private means that it cannot be accessed from outside of the class. The scope is a class field. It can be accessed by the entire class. There are many reasons why you would want to control access to a variable from being changed or even read from outside the class it is in.
dennis deems
Ranch Hand

Joined: Mar 12, 2011
Posts: 808
Consider a public class Course which has a private reference variable Student:



Now suppose a public class School where a method instantiates Course. When we look at Course from the class School, we will not be able to see the Student variable.
karan bhalla
Greenhorn

Joined: Jul 07, 2011
Posts: 2
got it...
thanks both of you!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: private reference variable
 
Similar Threads
Polymorphics and Generics.... how to do specific things to a subclass
getName()
Understanding Exception handling
difference between reference variable and instance variable
Arrays: Calling input from other methods and classes