Inheritance is the ability to access methods and properties of the base class or parent class in the child class.
namespace Inheritance
{
// Base class or parent class for Manager class.
class Employee
{
public void EmpTask()
{
Console.WriteLine("Task for Employee");
}
}
//child class for Employee class
//base or parent class for Program class
class Manager:Employee
{
public void ManTask()
{
Console.WriteLine("Task for Manager");
}
}
//Child class for Employee and Manager Class
class Program:Manager
{
static void Main(string[] args)
{
Program obj = new Program(); //Instantiating Program class
//calling methods from Employee class and Manager class
obj.EmpTask();
obj.ManTask();
Console.ReadLine();
}
}
}
Join MindStick Community
You need to log in or register to vote on answers or questions.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Inheritance is the ability to access methods and properties of the base class or parent class in the child class.