Breaking News
Loading...
Friday 29 March 2013

Wht is Inheritance in c#,net,How to use Inheritance in C#.net


•    Inheritance is main concept of OOP it show the parent child relationship between classes
•    Inheritance is process in which one class get the properties and method from another class
•    It's technic of deriving new class from old class.  

Types of Inheritance:

1). Single Inheritance
2). Multilevel Inheritance
3). Multiple Inheritance
4). Hybrid Inheritance
5). Hierarchical Inheritance

 1). Single Inheritance
In single inheritance class B derived from class A




2). Multilevel Inheritance

In multilevel inheritance class B is derived from class A and class c is derived from class B


3). Multiple Inheritance

In multiple inheritance class C is derived from two class A and class B.
This type of inheritance is not supported in c#.net



4). Hierarchical Inheritance

In Hierarchical Inheritance Class B, class C and class D is derived from Class A.



5). Hybrid Inheritance


In Hybrid inheritance Class B and C derived from A and class d derived from class B, class C.


Example :


class A
    {
        void methodA()
        {
            Console.Write("This is Method A");
        }
    }

    // here class B is derived from class A so it calls single inheritance.....
    class B:A
    {
        void methodB()
        {
            Console.Write("This is Method B");
        }
    }

    // here class C is derived from class B and class B is derived from class A so it call multilevel
    class C:B
    {
        void methodC()
        {
            Console.Write("This is Method C");
        }
    }

    // here class D,E and B call derived from A so it call hierarchical inheritance
    class D:A
    {
        void methodD()
        {
            Console.Write("This is Method D");
        }
    }
    class E: A
    {
        void methoda()
        {
            Console.Write("This is Method A");
        }
    }

See Also :
  Follow Me On Facebook

--
/\/ir@\/  <(.'.)>

0 comments:

Post a Comment

Thanks for comment

 
Toggle Footer