Page Stats
Visitor: 335
C#.Net Inheritance
Inheritance is the ability to inherit the properties of one class into another class without redefining it. Inheritance provides the code reusability.
Types of Inheritance:
1. Single Inheritance: A class is inheriting property of another class. (only one superclass)
2. Multilevel Inheritance: A class is inheriting property of another, and that class is inheriting property of third class.(several super classes)
3. Multiple Inheritance: A class is inheriting property of multiple classes. C# does not support multiple inheritance means we cannot inherit more than one class in a class. But, using interfaces we can implement multiple interfaces. (one superclass, many subclasses)
4. Hierarchical Inheritance: It is like a tree structure, a parent class is inheriting by two or more child classes. (subclass derived from another subclass)
Access Modifiers:
Modifiers can indicate the visibility of a method.
Modifiers | Meaning |
---|---|
public | Class accessible from anywhere |
protected | The item is visible only to any derived type. |
none or internal | Accessible within a class only. |
private | The item is visible only inside the type to which it belongs. |
Types of Inheritance