
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# Example for Hierarchical Inheritance
More than one class is inherited from the base class in Hierarchical Inheritance.
In the example, our base class is Father −
class Father { public void display() { Console.WriteLine("Display..."); } }
It has Son and Daughter as the derived class. Let us how to add a derived class in Inheritance −
class Son : Father { public void displayOne() { Console.WriteLine("Display One"); } }
Example
The following the complete example of implementing Hierarchical Inheritance in C# −
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Inheritance { class Test { static void Main(string[] args) { Father f = new Father(); f.display(); Son s = new Son(); s.display(); s.displayOne(); Daughter d = new Daughter(); d.displayTwo(); Console.ReadKey(); } class Father { public void display() { Console.WriteLine("Display..."); } } class Son : Father { public void displayOne() { Console.WriteLine("Display One"); } } class Daughter : Father { public void displayTwo() { Console.WriteLine("Display Two"); } } } }
- Related Questions & Answers
- C# Example for MultiLevel Inheritance
- C# Example for Single Inheritance
- Hierarchical Inheritance in Dart Programming
- Inheritance in JavaScript with example
- What is Inheritance in Java? Explain with an example
- C# and Multiple Inheritance
- Multiple Inheritance in C++
- Explain Inheritance vs Instantiation for Python classes.
- Hierarchical Database Model
- Hierarchical Data Model
- Interfaces and Inheritance in C#
- What is Inheritance in C#?
- Inheritance vs Composition in C#
- Delegation vs Inheritance in C#
- Inheritance in C++ vs Java
Advertisements