Erik Movsesyan

Erik Movsesyan

  • NA
  • 62
  • 5.9k

Why are derived class fields initialized before the base class fields

Jul 23 2022 12:01 PM

I know that the following is the order of data members initialization and constructor call when creating a derived class object.

  1. Derived static fields
  2. Derived static constructor
  3. Derived instance fields
  4. Base static fields
  5. Base static constructor
  6. Base instance fields
  7. Base instance constructor
  8. Derived instance constructor
     

Everything here seems pretty logical except for ONE thing:
I can not understand why is that that derived class fields get initialized before base class fields? Honestly I can not find any valid and logical explanation for that after scouring the internet and giving it a lot of thought.


Answers (3)