
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
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 Articles
- C# Example for Single Inheritance
- C# Example for MultiLevel 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++
- Hierarchical Database Model
- Hierarchical Data Model
- Interfaces and Inheritance in C#
- What is Inheritance in C#?
- Delegation vs Inheritance in C#
- Inheritance vs Composition in C#
- Inheritance in C++ vs Java
- Inheritance and friendship in C++

Advertisements