Why does a derived class constructor always access the base class constructor?

I saw this question in one of my question docs:

Why should the constructor of the derived class always refer to the constructor of the base class?

I am wondering if the question is really?

+3
source share
7 answers

So that you can have a valid Base object before you start messing around with the inherited functions of your derived object!

+4
source

. "": , , , , , , .

+3

, .

, Java . , . , , Object , .

+2

, .

+1

, .

+1

, . , , , .

+1

, - . .

, super() subclasses.

The visible part of building a class is initializing the fields. But there is still under the hood (memory allocation, registration, etc.). All of this must be done for all superclasses when creating a derived class.

+1
source

Source: https://habr.com/ru/post/1747484/


All Articles