 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP 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 Single Inheritance
The following is an example of Single Inheritance in C#. In the example, the base class is Father and declared like the following code snippet −
class Father {    public void Display() {       Console.WriteLine("Display");    } } Our derived class is Son and is declared below −
class Son : Father {    public void DisplayOne() {       Console.WriteLine("DisplayOne");    } } Example
The following is the complete example to implement Single Inheritance in C#.
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace MyAplication {    class Demo {       static void Main(string[] args) {          // Father class          Father f = new Father();          f.Display();          // Son class          Son s = new Son();          s.Display();          s.DisplayOne();          Console.ReadKey();       }       class Father {          public void Display() {             Console.WriteLine("Display");          }       }       class Son : Father {          public void DisplayOne() {             Console.WriteLine("DisplayOne");          }       }    } }  Output
Display Display DisplayOne
Advertisements
 