Win a copy of Svelte and Sapper in Action this week in the JavaScript 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

instance members vs static members

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please check this out..
it should be helpful
Class vs Instance
Cheers,
John
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic