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 Types of Variables? 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 "Types of Variables?" Watch "Types of Variables?" New topic
Author

Types of Variables?

sonir shah
Ranch Hand

Joined: Nov 01, 2001
Posts: 435
Hello
What is the difference between
a) Instance Variables
b) Local Variables
c) Member Variables
Are they the same? if not give proper explainations
Roopa Bagur
Ranch Hand

Joined: Nov 03, 2000
Posts: 267
Local Variables : variables that are declared inside a method or instance initializer blocks.They only have scope with the code block where they are declared. They have to be initialised & are not assigned any default values.
Instance Variables : variables that require you to create an instance of the class to access them. They have class scope. Member variables are instance variables & they are assigned default values.
Default values :
false for boolean type
null for object type
0 for primitives
'\u0000' for char type
arrays of object type - null in each element.
arrays of primitive type - 0 in each element.
Originally posted by sonir shah:
Hello
What is the difference between
a) Instance Variables
b) Local Variables
c) Member Variables
Hope this helps.
Anybody else.. do fill in what I have missed.
Are they the same? if not give proper explainations

sonir shah
Ranch Hand

Joined: Nov 01, 2001
Posts: 435
Can you give me a few examples of the above types of variables showing when to use them and how ?
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi Sonir,
<pre>
class VarExamples{
static int classVariable;
int instanceVariable;
void doSomething(){
int localVariable;
}
}

</pre>
Class variables and instance variables are also 'member variables'
Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
Co-author Mike Meyers' Java 2 Certification Passport


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
 
Don't get me started about those stupid light bulbs.
 
subject: Types of Variables?
 
Similar Threads
Why Java ?
Opening .bat files from ant
Variables in Java
Runtime.getRuntime() help plzzzzzzzz
Variables