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
posted
0
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
posted
0
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
posted
0
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!