Difference of Class Variable and Instance Variable

I am new to Java Technology. Can anyone explain me the difference between class variable and instance variable, class methods and instance methods, and also class members?

This are  the basic terms, in which , we need to be strong with out any confusions.

1. class members : members declared in a class. Both data members (variables declared in a class) as well as member functions (methods declared as in a class).

2. class varibale : a  data member  which is declared  with static modifier.

3. Instance variable : a data member in a class with out static modifier.
The main difference between the class variable and  Instance variable is,
first time, when class  is loaded in to memory, then only memory is allocated for all class variables.
That means, class variables not depends on the Objets of that classes. what ever number of objects are there, only one copy is created at the time of class loding.
The main advantage of this class variable is, suppose if we want to maintain a counter to count the no of object of type that class, in that case we use variable counter as the static variable.

4. Class method : a method with static modifier.

5. Instance methos : a method with out ststic modifier.
For Both class methos and Instance method , memeory allocted only once, that is loading the class.
But difference is, we can access the static method, directly with class name , with out using object of that class.
Where as Instance method can be access through only Objects or other non ststic method of same class (This concept is called nested method).
Of course, we have some restrictions with static methods:

1. static method can use only static variables.
2. static method can not access through the non ststic method and  vice versa.

This  is the minimum information, we need to know as a basic concept.

Siva

Java Tips

See also

Do you have a Java Problem?
Ask It in The Java Forum

Java Books
Java Certification, Programming, JavaBean and Object Oriented Reference Books

Return to : Java Programming Hints and Tips

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.
The site www.erpgreat.com is not affiliated with or endorsed by any company listed at this site.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
 The content on this site may not be reproduced or redistributed without the express written permission of
www.erpgreat.com or the content authors.