Inheritance
Structors does not support inheritance.
In Inheritance, child class members can consume members of parent class (except private members of parent class)
6 points related to inheritance
1. Parent class constructor must be accessible to child class else inheritance wont work.
2.Child class members can access parent class members butt parent class members can never access any members that are defined purely in the child class.
3. We can initialize parent class variable using child class instance.
ParentClass obj = new ChildClass();
4. Every class (predefined or custom defined) has a default parent class- object. So, we can use Equals(), GetHashCode(), GetType(), ToString() from anywhere.
5. C# does not support multiple inheritance.
6. Whenever child class constructor is called it will implicitly call constructor of parent class, only if constructor is parameter less.
If the constructor of class is parameterised, child class constructor can not call parent class constructor implicitly. To overcome this, programmer must explicitly call parent class constructor from child class constructor, and pass value to those parameters. This can be done using base keyword.
Structors does not support inheritance.
In Inheritance, child class members can consume members of parent class (except private members of parent class)
6 points related to inheritance
1. Parent class constructor must be accessible to child class else inheritance wont work.
2.Child class members can access parent class members butt parent class members can never access any members that are defined purely in the child class.
3. We can initialize parent class variable using child class instance.
ParentClass obj = new ChildClass();
4. Every class (predefined or custom defined) has a default parent class- object. So, we can use Equals(), GetHashCode(), GetType(), ToString() from anywhere.
5. C# does not support multiple inheritance.
6. Whenever child class constructor is called it will implicitly call constructor of parent class, only if constructor is parameter less.
If the constructor of class is parameterised, child class constructor can not call parent class constructor implicitly. To overcome this, programmer must explicitly call parent class constructor from child class constructor, and pass value to those parameters. This can be done using base keyword.
No comments:
Post a Comment