aspose file tools*
The moose likes Beginning Java and the fly likes object and instance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "object and instance" Watch "object and instance" New topic
Author

object and instance

in.anurag Singh
Greenhorn

Joined: May 14, 2010
Posts: 25
hey,
I attended an interview where i was asked about the difference b/w Object and Instance. but i was unable to give the answer. will you please explain the difference with a suitable example.
Vineet Kakati
Greenhorn

Joined: May 03, 2010
Posts: 21
When you create a Java object by calling its constructor, the object reference that is returned is called an instance. There is little difference between the two terms. The word instance is usually used when we talk about the process of object creation or instantiation, it is a single reference to an object.
in.anurag Singh
Greenhorn

Joined: May 14, 2010
Posts: 25
hmm,
got a little, but is not satisfactory answer..
I want a little more description.
will you please explain the answer with a Java code.
Lamont Williams
Greenhorn

Joined: Apr 28, 2004
Posts: 2
Check out this link: http://java.about.com/od/workingwithobjects/ss/designobjects_6.htm

From my understanding, you create an instance of an object. Thus, there lies the difference.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14269
    
  21

Lamont Williams wrote:From my understanding, you create an instance of an object. Thus, there lies the difference.

No...

An object is an instance of a class. You create an instance of a class, and that's an object. The words "object" and "instance" refer to the same thing - but you use the word "instance" when you're talking about how the object relates to its class.

A class is a blueprint that describes how to create objects - those objects are instances of that class.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Lee Kian Giap
Ranch Hand

Joined: Jan 23, 2008
Posts: 213
hmm ... another funny interview question ... which doesn't help to get good candidate

the question asking
1) general term "object" ?
or
2) Object class in Java ?

if question is (2) , then no need explain ... a big difference

if question is (1) ,
object represent an element (since it is singular) in problem space
instance means an object that created from a particular class

Why ? wHy ? whY ? ask this kind of question in interview ?


SCJP 6, SCWCD 5, SCBCD 5
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

Lee Kian Giap wrote:
Why ? wHy ? whY ? ask this kind of question in interview ?


Well, that's one way to look at it. Here is another...


There are a few ways to answer this question. (1) Do not give an answer, a wrong answer, etc. -- which is really bad. (2) Just say that they are the same thing -- which may be correct, but is also bad. Or (3) use it to start a discussion. Talk about how the two words are used interchangeably in most cases. Talk about how it could be actually be about the Object class. And tons of details related to it. etc.

Vague questions can be used to talk about lots of stuff, or even lead the interviewer. The goal of an interview is to give the interviewer a view into how you think -- short answers, whether correct or not, doesn't really accomplish that.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
Consider Paul's rocket mass heater.
 
subject: object and instance