views:

119

answers:

7

What is the difference between an Instance and an Object? Is there a difference or not?

+4  A: 

An instance is an object in memory. Basically you create object and instantiate them when you are using them.

Here is a nice writeup on Classes Vs Objects Vs Instances, he is talking Java but it applies to all OO.

http://alfredjava.wordpress.com/2008/07/08/class-vs-object-vs-instance/

Dustin Laine
+1  A: 

well, in my bad english, an object is a construct. Something static that has certain features and traits, such as properties and methods, it can be anything. A string, a usercontrol, etc

an instance is a unique copy of that object that you can use and do things with. Imagine a product like a computer.

THE xw6400 workstation is an object

YOUR xw6400 workstation, (or YOUR WIFE's xw6400 workstation) is an instance of the xw6400 workstation object

hope thats not too muddy of an answer

Lerxst
A: 

An object can be a class, say you have a class called basketball.

but you want to have multiple basketballs so in your code you create more than 1 basketball

say basketball1 and basketball2. Then you run your application. You now have 2 instances of the object basketball.

Darxval
That would mean a Object is a Instance of a Class Constructor ?
streetparade
think of the object like a blueprint. say we have a blueprint for the basketball, that is the class. when the basketball is created and made it now exists, so that would mean we have 1 instance of the object basketball. if we built another basketball from the object(blueprint). we now have 2 instances of the basketball. There is always just 1 object, but we can make many instances of that object.
Darxval
+1  A: 

An instance is a specific representation of an object. An object is a generic thing while an instance is a single object that has been created in memory. Usually an instance will have values assigned to it's properties that differentiates it from other instances of the type of object.

TLiebe
+2  A: 

Excellent question.

I'll explain it in the simplest way possible: Say you have 5 apples in your basket. Each of those apples is an object of type Apple, which has some characteristics (i.e. big, round, grows on trees).

In programming terms, you can have a class called Apple, which has variables size:big, shape:round, habitat:grows on trees. To have 5 apples in your basket, you need to instantiate 5 apples. Apple apple1, Apple apple2, Apple apple3 etc....

Alternatively: Objects are the definitions of something, instances are the physical things.

Does this make sense?

yuval
+1  A: 

There's no real significant difference that should consume too much of your time. There might be some fancy language that some people might take up a lot of spaces to write about, but at the end of the day, as far as a coder, developer, programmer, architect, is concerned, an instance of a class and an object mean the same thing and can often be used interchangeably. I have never met anyone in my career that would be picky and spend half hour trying to point out the differences, because there's really none. Time can be better spent on other development efforts.

Khnle
A: 

Let's say you're building some chairs.

The diagram that shows how to build a chair and put it together corresponds to a software class.

Let's say you build five chairs according to the pattern in that diagram. Likewise, you could construct five software objects according to the pattern in a class.

Each chair has a unique number burned into the bottom of the seat to identify each specific chair. Chair 3 is one instance of a chair object. Likewise, memory location 3 can contain one instance of a software object.

So, an instance (chair 3) is a single unique, specific representation of an object (a chair).

Brian Showalter