Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Can anyone please tell me the difference between object and instance in oops? This question i faced during interview.

Thanks in advance
Posted

The words "template," and "blueprint" are very good descriptions of what the code for a Class, or Struct, or Form, or UserControl, or Component, or Window, or Program.cs file ... is.

Those descriptions of objects are rendered into "real" objects (instantiated, created) ... that "exist" in memory ... in stages in .NET: it is compiled (translated, built) into MSIL intermediate code; that intermediate code is compiled by the JIT compiler, and the jitted code is executed by the .NET run-time engine. The objects you have told the compiler you want to create instances of have had had memory allocated for them, and that memory is used to hold the data for the object's internal structure.

What you have at run-time are references to these instantiated objects which you can use to access the internal data and state of the objects that is exposed.

An instantiated object is not a copy of a Class, or Struct, or whatever, just as a house is not a copy of a set of blueprints.
 
Share this answer
 
And object is the declaration of a type, which it's properties, methods and so forth: and instance is the example of the type that you can manipulate.

Think of cars: Car is the object, but "my car", "your car", "this car", and "that car" are the instances. You may be able to "drive a Car", but you need an instance of it to get to the shops!
 
Share this answer
 
Comments
Rob Philpott 17-Feb-15 12:16pm    
Not wishing to be argumentative here, but that's not the way I see it. Maybe this is correct in OOP parlance, but I'd argue not in .NET.

To my mind, things such as a car are types. Objects only arise out of instantiation, whereby I end up with an object of type Car. Then it gets all gets quite confusing because the base type is called - Object. But despite being called Object it is a type.

This leads to the unsatisfactory answer that objects and instances are essentially the same thing. Thinking back to my days of C++ though, I don't think the word 'type' existed formally but its such a long time ago I can't remember.

Anyway, what the hell. You're probably right. :)
An instance is a unique copy of a Class that representing an Object.
Class is a “template” / “blueprint” that is used to create objects.

Refer :

1 ) What is the difference between an Instance and an Object?

2 ) Class vs Object vs Instance

3 ) Difference between Object and instance : C++
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900