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...
I was asked a question in an interview and i wasn't able to answer it... Here is the question
My answer was it is an other name of an object
... what is the right answer for this question...
Instance is to class as cake is to recipe. Any time you use a constructor to create an object, you are creating an instance.
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.
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.
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.
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."