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