=> Inheritance is reusability of the code.
=> Inheritance is a mechanism of acquiring the features and behaviours of a class by another class. The class whose members are inherited is called the base class, and the class that inherits those members is called the derived class.
Example :-
namespace Inheritance
{
class Program
{
static void Main(string[] args)
{
child child = new child();
child.print();
Console.ReadLine();
}
}
class Parrent
{
public Parrent()
{
Console.WriteLine("Parrent constrocter calling");
}
public void print()
{
Console.WriteLine("I am parrent class");
}
}
class child:Parrent
{
public child()
{
Console.WriteLine("Child constrocter");
}
}
}
Parrent constrocter calling
I am parrent class
Child constrocter
0 comments:
Post a Comment