What is the value of a instance variable when we have 2 objects. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is the value of a instance variable when we have 2 objects.

As we can create multiple objects in a class and they can have diffrent instance variable values. Let there are two objects dog and cat of class animal. There is a instance variable declared String animalsound; I use these methods to set its value. cat.setSound (meww meww); dog.setSound (woof woof); So what is the value of animalsound variable after applying these methods.

20th Mar 2017, 1:18 PM
Narender Yadav
Narender Yadav - avatar
1 Answer
+ 1
Before creating the object this class is like a blueprint. You can create any number of object of this class. Right!!! So if you a set a property to a particular object then that property can be accessed only by that object . An instance value can't exist alone. And if you access this member variable directly it will pop up an error.
20th Mar 2017, 1:43 PM
Bhabesh Gogoi
Bhabesh Gogoi - avatar