This week's giveaway is in the Testing forum.
We're giving away four copies of TDD for a Shopping Website LiveProject and have Steven Solomon on-line!
See this thread for details.
Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Types of Variables?

 
Ranch Hand
Posts: 435
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Destroy anything that stands in your way. Except this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic