Sunday 19 April 2015

What is inheritance in c# with example?


Inheritance represents a kind of relationship between two classes. When a new class needs same members as an existing class, then instead of creating those members again in new class, the new class can be created from existing class, which is called as inheritance.
Types of inheritance:-
      1-Single inheritance (only one base class)
2-Multiple inheritance (several base classes)

1-    Hierarchical inheritance(one base class, many subclasses)
2-    Multilevel inheritance(derived from a derived class)
Example of inheritance:-
using  System;
public class Item
{
Public void company()
{
Console.writeline(“Item code =xxx”);
}
}
Public Fan : Item
{
Public void Model()
{
 Console.writeline(“fa model “);
}
}
Public simpleinheritance
{
Public static void main()
{
Item itm = new Item();
Fan fan = new Fan();
Itm.company();
Fan.company();
Fan.company();
}
}

No comments:

Post a Comment