wood burning stoves*
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "object and instance" Watch "object and instance" New topic

object and instance

in.anurag Singh

Joined: May 14, 2010
Posts: 25
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

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

Joined: May 14, 2010
Posts: 25
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

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: 14074

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


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 7 API documentation
Scala Notes - My blog about Scala
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" ?
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 ?

Henry Wong

Joined: Sep 28, 2004
Posts: 18509

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.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Consider Paul's rocket mass heater.
subject: object and instance
Similar Threads
object Vs instance
Difference between Object and Instance
Related to Object
object Vs instance
what is the difference??