• 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
hi friends
can any one explain what is subtle diff betwn instance and object or do they are same things?
 
Rajagopal Manohar
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think they are the same,

except that there is a class called Object in java from which all other classes are derived.

many times objects and instances are used to denote the same thing i.e. A class that has been given some space in memory
 
ganesh pol
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
RAJ
ARE U SURE ABOUT IT THAT THEY ARE SAME THING AND THEY DO NOT HAVE ANY DIFFERENCE.
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We normally think of an instance as an object formed by using the class as a template. So, different instances of the same class can have different state, but all refer to the same code.

However, in the Java runtime each class, interface, array, primitive and the keyword void will have its code also available in the form of an object which is an instance of java.lang.Class. Whenever we compile any Java file, the compiler will embed a public, static, final field named class, of the type java.lang.Class, in the emitted byte code. This field can be accessible like this:

java.lang.Class class = Myclass.class;
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a very frequently asked question, so I just created http://faq.javaranch.com/view?ObjectVsInstance

You might also want to do a search on this forum.
 
Megs Maquito
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
an object is an instance of a class.
 
Nischal Tanna
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Megs Maquito:
an object is an instance of a class.


Good reply ... just like using both the words and creating a sentence
[ June 07, 2005: Message edited by: Nischal Tanna ]
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to poke Ilja with a stick now & then ... The FAQ points out that "a link is an instance of an association" which is maybe a different case than "object is an instance of a class" or maybe not. If "Association" or "RUP" are classes in a meta-model, then a link or a process are "concrete" instances. You might have to allow for instantiating objects in your brain instead of computer memory to make this work.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Stan James:
Just to poke Ilja with a stick now & then ... The FAQ points out that "a link is an instance of an association" which is maybe a different case than "object is an instance of a class" or maybe not. If "Association" or "RUP" are classes in a meta-model, then a link or a process are "concrete" instances. You might have to allow for instantiating objects in your brain instead of computer memory to make this work.


Yes, if you like to call RUP a class and the resulting process an object, that would work. I don't think I typically do that, though...
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Probably nobody but the developers of Rose think that way. But I'm sure even they have some meta-meta-meta level where it gives out. (End poking with stick)
[ June 07, 2005: Message edited by: Stan James ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic