Y
Y
Yury Trofimov2018-12-01 22:05:10
OOP
Yury Trofimov, 2018-12-01 22:05:10

Object or Instance?

Good day. I study c# on video courses, got close to classes and objects. As I understand it, when creating objects, one object is created (combines everything that is repeated in each object) and class instances (combines everything that is different). If I misunderstood, please correct me. Question: Class1 Example = new Class(); - here I reserve memory for a class instance and for an object at the same time? How should one think: did I create an object here?
Class1 Example2 = new Class(); - the object has already been created (from above), so here I reserve memory only for the next instance of the class? How should I think: did I create an instance of the class here?
https://yadi.sk/i/82ose5d3BWaOjg - my thoughts in the picture
Thanks in advance for your answers)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dasha Tsiklauri, 2018-12-02
@1trofimov

Yes, that's right, only the terminology is chosen unsuccessful. An object is a part in RAM that is referenced by all instances of the generated classes. And that part is methods. Separate methods and fields. under the fields of all instances, a separate memory is allocated for each. methods is a table of virtual functions, if the method is general, then its meta-information is described in one place, at the time of the call, links to one or another instance are thrown to it. This is how prototypal inheritance works in javascript.
upd: in order to better understand such things, as a rule, they read the discipline of organizing computers and systems, where you ultimately answer the questions:
- what assembler instructions the creation of an instance turns into
- how data is represented in memory
- what is common between them

S
Stalker_RED, 2018-12-01
@Stalker_RED

The class is the letters that you see on the screen.
Imagine it as a drawing, for example. And ready-made objects exist in the computer's memory while the program is running. Imagine them as a bunch of some gizmos made according to a common drawing.
Objects are instances of a class.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question