Ask your own question, for FREE!
Computer Science 17 Online
OpenStudy (anonymous):

what is the difference between object and instance in object oriented programming?

OpenStudy (nethwa):

An instance is an object created with a class. So basically instance and object are the same.

OpenStudy (anonymous):

um they r same?!

OpenStudy (anonymous):

@NeThWa wrong! An instance is a copy of your object which is created on demand in runtime. Object itself is the class you defined which holds variables and methods. That's the power of the oop, you can have many instances of a single object at the same time.

OpenStudy (anonymous):

um i thot that class is a blue print/template for an object....... object nd class r the same?

OpenStudy (anonymous):

When you create a class, you're defining an object. When you use that class in your program, you're creating an instance of the object. Consider instance as a copy of your object living in your memory and getting deleted once the program is closed. Object can refer to instance but in general, it's referring to the class itself. We create a new "instance" of the object/class. we don't create a new "Object" of the class. To sum it up, when you create an object by calling its constructor, the object reference that is returned is called an instance.

OpenStudy (anonymous):

I dont know if my explanation makes any sense to you but that's what it is

OpenStudy (anonymous):

well it's sorta confusing

OpenStudy (anonymous):

When you create an object (for example public car myCar = new car();), you receive a reference to it(myCar) which is called an instance of the object (car). You can have multiple instances of a single object and each of them holding different values.

OpenStudy (anonymous):

so ur car and some x's car are instances of object car......nd wat's the class here?

OpenStudy (anonymous):

class = object = car

OpenStudy (anonymous):

i was reading this stantement in some file "differentiate the notion of an object from that of a class. The easiest way to understand the distinction is to think about a class as a pattern or template for objects that share a common behavior and collection of state attributes."

OpenStudy (anonymous):

Well there aren't any strict rules about calling what a class and what an object so that text is true. I remember when I read my first C++ book it said class and object is the same.

OpenStudy (anonymous):

um ok.....thanks anywayz....@c0rtez and @NeThWa

OpenStudy (nethwa):

@c0rtez I've learned that it's basically the same^^ Might be, that you've learned something else, i also heard definitions of instances as the objects within the object (e.g. the x- and y-coordinates in the class point are the instance of the object created with the class) but that sounds really wrong to me^^

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!