In C#, when we create a inherited class object is it creating a base class object also?Got confused because its calling the base class constructor from children's class constructor.
Will calling a base class constructor from child class constructor, create a base class object?
Only one object is created but it has two "layers" - the base class properties and behaviours and the inherited class properties and behaviours. So in one sense the answer is "Yes, a base class object is created" (that object has the same properties and behaviours as any other base class object) but it's the same object as the inherited class so it's also true to say "No, a base object is not ALSO created.". The key difference is the "also".
The fact that one object can seem to be two different things (or more) is at the heart of object orientation. It's what makes it both powerful and complicated.
No it will not create an objects of the base class, the inherited class's objects can have accessibility to the base class properties(according to the protection level). so that the particular members(available to the inherited class) are only initialized, no object of base class is created.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With