• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Is their any difference b/w class variable and instance variable

 
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ranchers,

I have this stupid doubt whether their is any difference between instance variable and class variable.

I think they are two different terminologies used for same purpose.But certain explanations have forced me to think again and again.

Help me out please...
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Both are very different kinds of variables used in the java world.
You need lot more explanation in this regard but this is not the right place
to discuss all that stuff .
YOU refer Head First java
 
srinivas sridaragaddi
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Madhu,

Can you give me link which can help me in better understanding about this topic

Thanks in advance
 
Ranch Hand
Posts: 320
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I do not know another way to pass a link, but I had some comments on this in another thread in another section just this morning...

https://coderanch.com/t/407808/java/java/Static-Variable
 
srinivas sridaragaddi
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi bob

you can send a private message and send your links through that mail.It will be a great help dude
 
srinivas sridaragaddi
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi i found the difference, its not very detailed but basic difference is given and the link is
http://www.sap-img.com/java/difference-of-class-variable-and-instance-variable.htm
 
Ranch Hand
Posts: 1609
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Static variables are also known as class variables, because they belong to class not to any specific instance.

Instance variables are non-static variables because each instance has its own copy.
May be you can try this...
1. Declare a class have a varibale say public int i=10;
2. in the main have two objects of this class, let first one (say obj1) set its value 20 and the other one (say obj2) set its value 30.
3. print them both using dot operator (say obj1.i and obj2.i ).
4. Do the same but change i to static as public static int i=10.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by srinivas sridaragaddi:
hi bob

you can send a private message and send your links through that mail.It will be a great help dude


No, please just post the link - use the forum, not e-mail, so that others can also find the information.
 
She's brilliant. She can see what can be and is not limited to what is. And she knows this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic