C# Inheritance – programs for practice

(Last Updated On: February 26, 2019)

Q) What is output of below C# code?

View Answer
Output: Car is running

Explanation:In fact, this is name hiding feature in C# language. If base class and derived class have same method name and have not used virtual and override in base and derived class respectively then on creating object of derived class and assigning to base reference will call base class method. Recommended to read name hiding feature in C# with example

Q) What is output of C# program example?

View Answer
Output: Child
Explanation: In this C# code example, method overriding feature has been implemented. For overriding, the method should be virtual in base class and the same method in derived class preceding by override keyword. Read in detail about method overriding in C# language