views:

197

answers:

7

I was asked a question in an interview and i wasn't able to answer it... Here is the question

  • How will you define an instance[c#]?

My answer was it is an other name of an object... what is the right answer for this question...

+9  A: 

Instance is to class as cake is to recipe. Any time you use a constructor to create an object, you are creating an instance.

Adam Ruth
+1 love the analogy :-)
marc_s
+2  A: 

MyObject obj = new MyObject( );

Muad'Dib
That's not an explanation, that's a line of code.
Aaronaught
That is how I "define an instance"
Muad'Dib
No, that is how you **construct** an instance. That's not a definition. Interview questions like this are generally intended to test a programmer's ability to communicate effectively. Is this how you would explain it to Doris in Accounts Receivable?
Aaronaught
If Doris in Accounts Receivable was interviewing me, I wouldn't want the job.
Muad'Dib
+4  A: 

I would describe instance as a single copy of an object. There might be one, there might be thousands, but an instance is a specific copy, to which you can have a reference.

Nick Craver
+2  A: 

Class is the blueprint, instance is the completed construction.

Benny
A: 

yup, my interpreteation would be to mention that only classes can 'define' instances. or something along those lines, I might mention an example in code, or seek clarification of the question.

indifferentDrum
A: 

a class is akin to a blueprint while an instance is a concrete implementation of the class/blueprint. An instance is also characterized by its identity, state and behavior.

Athens
A: 

An "instance" is an object allocated in memory, usually initialized by the compiler directive 'new, rendered according to the structure of a template which is most often a built-in language-feature (like a native data structure : a Dictionary, List, etc.), or a built-in .NET class (like a WinForm ?), or a user-defined class, or struct in .NET; or, even an Enum.

While an "instance" of a "class," for example, will embody, or contain, all the properties, fields, and methods of the class, the fields and/or properties may, or may not, have values allocated to them when the "instance" is created. The class template will also constrain the accessibility of the properties, fields, and methods inside any instance of the class.

The instance is "the real something" created from some "abstract plan for the something."

BillW