Teach Learn Teach
Users Online
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
Forum Threads
Latest Articles
Articles Hierarchy
C# Program to Demonstrate Single Inheritance
C# Program to Demonstrate Single Inheritance
This is a C# Program to illustrate single inheritance.
This C# Program Illustrates Single Inheritance.
Here In single inheritance we have single base class that is inherited by the derived class and the derived class has all the features of the base class and can add some new features and italso depends on the access specifier that is used at the time of base class inheritance.
Here is source code of the C# Program to Caluculate the power exponent value. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.
/* * C# Program to Illustrate Single Inheritance */ using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Inheritance { class Program { static void Main(string[] args) { Teacher d = new Teacher(); d.Teach(); Student s = new Student(); s.Learn(); s.Teach(); Console.ReadKey(); } class Teacher { public void Teach() { Console.WriteLine("Teach"); } } class Student : Teacher { public void Learn() { Console.WriteLine("Learn"); } } } }
This C# program is used to illustrate single inheritance. Here in single inheritance we have single base class that is inherited by the derived class. And the derived class has all the features of the base class and can add some new features and it also depends on the access specifier that is used at the time of base class inheritance.
In this program, we have created Teacher and Student class. Create the object variable for teacher class as‘d’ and for student class as‘s’. Then we are calling the teach() and learn() along with the object variable.