Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the basic differences between an Instance and an Object of the class?

Tags:

oop

What is the basic differences between an Instance and an Object of the class? I always have confusion about how exactly they are different.

like image 354
user2798056 Avatar asked Sep 25 '13 11:09

user2798056


6 Answers

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

Here is a nice article on Classes Vs Objects Vs Instances, he is talking Java but it applies to all object oriented programming: Class vs Object vs Instance

like image 142
karthik reddy Avatar answered Nov 10 '22 12:11

karthik reddy


What is the difference between 'human' and 'you'? 'Humans' is a class (there are a lot of humans), but 'you' are only one (you are an object of human). What is instance? There are some functions, which works not only for objects, but for class too. Examples: human::isMammal() == true, human::isArachnid() == false. You don't need an object of class human to call such functions (because these function don't use any special properties of objects: all humans are mammals and not arachnid), so it is enough to work with instance.

like image 42
Ilya Avatar answered Nov 10 '22 12:11

Ilya


To be simple,

Object is an instance of the class.

When people talk about object, it is more specific to a particular instance (values in variables in the class). I hope, I have at-least not confused you.

like image 34
Abhijith Nagarajan Avatar answered Nov 10 '22 14:11

Abhijith Nagarajan


I think most programmers would use "object" and "instance" interchangeably. Some pedants may try to draw distinctions, but such distinctions are meaningless if they are not recognized by the majority of users of the terms.

"Class", of course, is a sort of template or design for an object.

like image 31
Hot Licks Avatar answered Nov 10 '22 12:11

Hot Licks


An object is the definition of something while an instance is a manifestation if that thing. As an example, a chair by definition has a seat, 3 or more legs and a back. This would be the object. Note, we only have a definition and not an object itself. Now if we create a chair, wee have an instance.
In most languages the new operator is the way to create the instance...

 Chair c = new Chair();

There are other ways. In this case Chair is the object and c is the instance. We can easily create additional chairs as well which has no effect on the object definition.

like image 33
Jeff Avatar answered Nov 10 '22 14:11

Jeff


an instance is a specific realization of an object. when a application run ,in fact an instance of that program run for example if we have an object for car , a bmw can be an instance of that

like image 20
behzad Avatar answered Nov 10 '22 13:11

behzad