Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is diff betwn object and instance

 
ganesh pol
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Terry Rickson
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
L�szl� Kov�cs
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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*?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
sreedhara satuluri
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic