+ 1

Static

can someone explain the statement -there is only one" instance "of a static method......basically I want to know the meaning of instance....... by relating it to a real world example.

2nd Jan 2018, 1:05 PM
Shalini Jha
Shalini Jha - avatar
3 Respuestas
+ 15
instance of a class means its object instance variables means the properties associated with object of that class for example ::: the class animal have objects dog,cat etc & instance variables sound , name etc
2nd Jan 2018, 1:49 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 15
adding to my answer above ::: //i didn't read question fully , i am busy thinking something else //btw , u can see the code which i made earlier for some post //here u will see that static variable is not associated to any object , it is associated with the class //hope after seeing the code , no doubt will be left ☺ https://code.sololearn.com/cvfs7727ltDG/?ref=app
2nd Jan 2018, 2:37 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 1
Another way of thinking about it, we often think of a class as a blueprint. When we want to use it we "make an instance" using the new keyword which means our blueprint now has an actual object in existence. As Gaurav said, this class has instance variables, like its name, one exists for each real object we make. Static on the other hand means that it does not belong to an instance, but a class. And you've only written the class once haven't you :)
2nd Jan 2018, 2:32 PM
Dan Walker
Dan Walker - avatar