Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Types of Variables?

 
sonir shah
Ranch Hand
Posts: 435
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 267
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 435
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you give me a few examples of the above types of variables showing when to use them and how ?
 
Jane Griscti
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic