Users Online

· Guests Online: 48

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

C# Program to Demonstrate Single Inheritance

C# Program to Demonstrate Single Inheritance

 

 

This is a C# Program to illustrate single inheritance.

Problem Description

This C# Program Illustrates Single Inheritance.

Problem Solution

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.

Program/Source Code

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");
            }
        }
    }
}
Program Explanation

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.

Runtime Test Cases
 
Teach
Learn
Teach

 

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 0.74 seconds
10,846,201 unique visits