• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

diff types of Variables & methods

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can some one please explain me the diff between
Member Variable, Class Variable, Instance Variable, and Local Variable.
the same thing in case of methods, the diff between
Member Method, Class Method, Instance Method, and Local Method.
If possible can some one give me an example for better understanding. Thank you very much in advance.


------------------
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Komal,
I will give it a shot!
Class variable: Any variable declared at class level (not inside any method) that is defined as static. One variable exists for all objects created of the class.
Instance variable: Any variable declared at class level (not inside any method) that is not defined as static. Each object created of the class will have its own variable.
Member variable: Any variable declared at class level (not inside any method).

Class method: Any method in a class declared as static. Only one method will exist no matter how many objects are created of the class.
Instance method: Any method in a class not declared as static. Each object created of the class will have its own method.
Member method: Any method in a class

Regards,
Manfred.
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's some of it. I'm looking it up as I go along.
Instance variables
Each object has its own copy of the variable.
If the value is changed, it's changed for that instance only.
Example: int myVar = 12;
Class Variables
Also called Static variables. Declared with the static keyword.
There's only one copy available, and it's shared by all objects in the class.
If the value is changed, all objects "see" the new value.
Example: static int x = 12;
Another example is Math.PI - which will access the static variable PI (3.14....) in the Math class.
Class Methods
Also called Static methods. Declared with the static keyword.
Can be executed even when no objects exist.
Class methods can not refer to instance variables, only to class variables.
Example: Math.random() will execute the random method in the Math class.
Instance Methods
Can only be called by an object.
Example: object myObj would call method aMethod like this: myObj.aMethod();
Like I said, that's just some of it. I'm glad you asked this, because it's something I've been trying to understand, too, and writing it out like this (provided I've gotten it correct!) helps.
Susan

[This message has been edited by Susan Delph (edited May 02, 2001).]
 
Komal Mat
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you guys, for the explaination. I clears my confusion.
thank you very much
------------------
Komal Mat
 
reply
    Bookmark Topic Watch Topic
  • New Topic