C#C
C#3y ago
krixsick

❔ C# Inheritance Topic Question Mostly about base constructors

Hello! I just had some question regarding C# inheritance. So far, I have a few questions regarding on how inheritance works especially, the base constructors. I understand that inheritance is basically making a class a sub-class or child of a base class or parent. Because of this, the sub/child class can access the methods provided in the parent class. For base constructors, I can't really visualize on scenarios of using them effectively and how they function 100%. So far my questions are this:

  1. Do the fields inside both classes get shared when a class inherits from another class
  2. Using :base in the derived class' constructor makes the base class constructor called first, but why do we want this to happen? I understand that both constructors can take in different parameters and depending on those parameters, the fields will store that information type. But why do we have to initialize the base class if we initialize the derived class (child class)
Thanks!
Was this page helpful?