class parent_class
{
}
class child_class : parent_class
{
//Will simply move Data and Methods from the parent_class to the child class.
}
class Animal {
// fields and methods
}
// Dog inherits from Animal
class Dog : Animal {
// fields and methods of Animal
// fields and methods of Dog
}
//Example of inheritence
using System;
public class Parent
{
public string parent_description = "This is parent class";
}
//child class inherits parent class
public class Child: Parent
{
public string child_description = "This is child class";
}
class TestInheritance
{
public static void Main(string[] args)
{
Child d = new Child();
Console.WriteLine(d.parent_description);
Console.WriteLine(d.child_description);
}
}
// Parent Class
public class A
{
public void Method1()
{
// Method implementation.
}
}
// inherit class A in class B , which makes B the child class of A
public class B : A
{ }
public class Example
{
public static void Main()
{
B b = new B();
// It will call the parent class method
b.Method1();
}
}