Inheritance at compile time?


I was reviewing some codes and some concepts when I found the following assertion:


The inheritance mechanism in Java occurs at compile time, that is,   reuse of code by inheritance is unchanged in   run time

I spent a lot of time trying to understand the concept, but I confess I could not understand it, how so unchanged at run time? Is it correct that Java inheritance occurs at compile time? I always thought it was run-time.

asked by anonymous 21.11.2018 / 19:04

1 answer


Once set to "floor plan" type (class) you can not change anything inside it. Then any model is fixed by all the execution time, each field, field method, each type definition detail can not be changed. And all objects instantiated starting from this template will always be identical, it is guaranteed.

This is in contrast to dynamic languages where it is possible to change the composition of the model or specific objects during execution, which gives flexibility, but there is a loss of performance and robustness in the code, since it takes a whole treatment to deal with with this situation, optimizations are not possible because you do not know what you will find there, and at all times you can have a surprise.

Inheritance in Java is something conceptual, it occurs in the model and not in the object, so you inherit one model in another you are modeling now.

If you change the code and recompile the inheritance or the entire composition of each class can be set differently and the next execution will have the differences included.

21.11.2018 / 19:20