aspose file tools
The moose likes Beginning Java and the fly likes instance members vs static members Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "instance members vs static members" Watch "instance members vs static members" New topic
Author

instance members vs static members

Larry Lai
Ranch Hand

Joined: May 13, 2002
Posts: 44
Hi everyone,
Eventhough I have read the couple of books related to the instance members and static's, I couldn't clearly understand what's the difference between both of them?
instance members - instance variable and instance method
static members - static variable and static method

Thanks
see you
Larry
Hari babu
Ranch Hand

Joined: Jun 25, 2001
Posts: 208
Hi,
Instance members exists for instance of the class. For eg :
MyClass instance1 = new MyClass();
MyClass instance2 = new MyClass();
You assign a value to its member in the following way
instance1.member=1;
instance2.member=2;
If u want to acess a member variable or a method u call them on the instance created above. so instance Members doesnt exists until you create an instance of class.
Whereas Static members are those which will be shared across the instances, they exists without the existence of the instance.
For eg: If MyClass has static variable "staticMember", you can acess the same by
MyClass.staticMember=1;
MyClass.staticMethod();
Harish
John Mallavalli
Ranch Hand

Joined: Apr 24, 2002
Posts: 46
please check this out..
it should be helpful
Class vs Instance
Cheers,
John


Do not let what you cannot do interfere with what you can do !!<br /> <br />SCJP & SCWCD 1.4
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
John2000,
Thank you for the helpful link and welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner!


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: instance members vs static members
 
Similar Threads
Double-standard for inner class if it is non-static vs if it is static
non-static method isSenior() cannot be referenced from a static context
Instance members
Doubt: Main method
Why a Static method cannot refer to an instance variable?