What is a POO Instance


I've been programming for a while and whenever I read or hear the word instance , we instantiate , I get an idea of what is being talked about but I'm not sure at all.

I understand that the instance of an object is when we create a new object and we reserve a space in the memory:

Object obj = new Object();

Am I right? I forgot something? Is there any piece of information I'm missing?

asked by Asahi Sara 12.04.2016 в 08:55

2 answers


In Object Oriented Programming or POO, you have to distinguish two different concepts:

  • class : A class is a prototype or mold that indicates what characteristics they will have and how the elements created from that class will behave.
  • object : Objects are the elements created from the aforementioned classes. In some contexts or languages, the term instance is also commonly used

That is, from a class you can create infinite objects or instances.

Notice that the above definitions do not indicate where or how the object or instance is to be created and that is an irrelevant aspect in this case. In languages such as C ++, for example, you have the ability to choose whether the object will be created in the dynamic memory (heap) or in the stack of the program (stack):

class POO
  // ...

int main()
  POO a; // a se crea en el stack
  POO* b = new POO; // b se crea en el heap.

  delete b; // La memoria dinámica es necesario liberarla.

However, this does not have to be the case in all languages since each one has its own characteristics and the theory of object-oriented programming is independent of the language used.

answered by 12.04.2016 / 11:05

It is correct, and from then on that object will have all the methods of its class. This is true for java and for the other POO languages

answered by 12.04.2016 в 09:14