• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

what is diff betwn Object and instance

 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
RAJ
ARE U SURE ABOUT IT THAT THEY ARE SAME THING AND THEY DO NOT HAVE ANY DIFFERENCE.
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 coderanch, 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;
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
an object is an instance of a class.
 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
reply
    Bookmark Topic Watch Topic
  • New Topic