Instance variables vs class variables? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Instance variables vs class variables?

can anyone explain this in very simple no more then 2 lines lol. im thinking that when static is used a instance of class var is now just a class var.?

23rd Jul 2017, 8:07 AM
D_Stark
D_Stark - avatar
3 Answers
+ 2
instance variables are defined at instance level and can have a different value for each instance. static variables are defined at class level and share one value among the instances. For example, if you have a class Person with instance variable name and static variable numberOfPeople, you can instantiate several people with different names and at the same timekeep track of the overall number of people.
23rd Jul 2017, 8:47 AM
marit vandijk
0
straight to the point thanks!
23rd Jul 2017, 8:48 AM
D_Stark
D_Stark - avatar
0
@David you're welcome
23rd Jul 2017, 8:59 AM
marit vandijk