Forums Register Login

what is diff betwn object and instance

+Pie Number of slices to send: Send
what is diff betwn object and instance

i have seen in many books object and instance are used interchagebly what is subtle diff betwn object and instance
+Pie Number of slices to send: Send
It's safe to say an object is an instance or instantiation of a class. "instance" is used in more ways than this, so object and instance aren't quite equivalent, but they're close enough for most conversations.
+Pie Number of slices to send: Send
Hi,

If you look at this code.

Button b = new Button();

It creates a button object but the variable b is the instance variable of the Button object.

Hope this helps!
+Pie Number of slices to send: Send
that was my first thought too, but i guess Stan is right: what OP means is instance like when you use the new keyword - you instantiate something
+Pie Number of slices to send: Send
 

Originally posted by Terry Rickson:
Button b = new Button();

It creates a button object but the variable b is the instance variable of the Button object.



Surely b is a reference to the created object, and that object is an instance of the Button *class*?
+Pie Number of slices to send: Send
 

Originally posted by Terry Rickson:
H
It creates a button object but the variable b is the instance variable of the Button object.



Sorry, but that's incorrect terminology. An instance variable is a member variable of an object, used in contrast to class or static variable. "b" is a variable that refers to an object; that object is an instance of Button. But based on that one line of code, we can't tell if "b" is an instance variable or a local variable.
+Pie Number of slices to send: Send
the simple explanation is that....we declare a class and hence we need to declare that class into the main program..

The name of the class is object and the variable declared is the instance of the object



if any other answers then please let me know
+Pie Number of slices to send: Send
 

Originally posted by sreedhara satuluri:

The name of the class is object and the variable declared is the instance of the object



I think we've answered this one well enough now. These subsequent answers are just confusing (and generally wrong.)
I didn't say it. I'm just telling you what this tiny ad said.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 820 times.
Similar Threads
what is diff betwn Interface and Abstract class
what is diff betwn Object and instance
what is diff betwn jdk and jvm
diff betwn method and constructer
what is diff betwn java and javax?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 08:17:45.