Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

object and instance

 
in.anurag Singh
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15281
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Lee Kian Giap
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?

 
Henry Wong
author
Marshal
Pie
Posts: 21117
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic