wood burning stoves 2.0
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes instance/reference Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "instance/reference" Watch "instance/reference" New topic


b reddy

Joined: Apr 30, 2007
Posts: 7
what is the difference between an instance variable and an reference variable?
Meena R. Krishnan
Ranch Hand

Joined: Aug 13, 2006
Posts: 178
An Instance variable is a variable that is defined inside a class outside any method and without the 'static' modifier. These variables belong to each instance of the class' objects. These variables get initialized when an instance of the class is created.

A reference variable is used to access an instance of an object.

[ April 30, 2007: Message edited by: M Krishnan ]
vish vodeyar

Joined: Apr 26, 2007
Posts: 4
An object that belongs to a class is said to be an instance of that class. The variables that the object contains are called instance variables.

There is a special portion of memory called the heap where objects live. Instead of holding an object itself, a variable holds the information necessary to find the object in memory. This information is called a reference or pointer to the object. In effect, a reference to an object is the address of the memory location where the object is stored. When you use a variable of class type, the computer uses the reference in the variable to find the actual object.This variable is called the reference variable.

I think i have explained this concept to the best of my knowledge.
thanks and regards
I agree. Here's the link: http://aspose.com/file-tools
subject: instance/reference
It's not a secret anymore!