D
D
Denis Bredun2020-07-07 17:31:24
C++ / C#
Denis Bredun, 2020-07-07 17:31:24

How does the heap show or record that, for example, class B inherits from class A?

There is a code:

class A
{

}
class B : A
{

}


So, how is it marked in the heap that class B is inherited from class A?

Also, if we write B b = new B(); in the Main method, then we will first call the static constructor in class B, then the static constructor in class A, then the dynamic constructor in class A, and the dynamic constructor in class B. Why us the dynamic constructor of class A is called? We don't create an object of class A, after all. What happens under the hood when the dynamic constructor of class A is called. Why is this happening? I didn't find anything about this in Richter's book.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
#
#, 2020-07-07
@Luffy1

no way. this is written in the program text, and the ps compiler builds the sequence of calls

if we write B b = new B(); in the Main method, then we will first call the static constructor in class B, then the static constructor in class A, then the dynamic constructor in class A, and the dynamic constructor in class B.
and don't bother with static at all until you really understand what it is. this is not very clear at the initial stages of learning, and it definitely should not be taken into account until you get to the need to create your own overrides of static constructors

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question