Download presentation
Presentation is loading. Please wait.
1
Inheritance AKEEL AHMED
2
Overview Inheritance Types of inheritance Constructor in Inheritance
Virtual Methods Function Overloading
3
Inheritance Inheritance is the process by which one object can acquire the properties of another object. Inheritance is a "is a kind of" relationship. It supports the concept of classification in which an object needs only define those qualities that make it unique within the class. Inheritance involves a base class and a derived class. The derived class inherits from the base class and also can override inherited members as well as add new members to extend the base class. A base type represents the generalization, whereas a derived type represents a specification of an instance
4
Inheritance (Example)
5
Types of inheritance
6
Single inheritance It is the type of inheritance in which there is one base class and one derived class.
7
Single inheritance(Example)
8
Hierarchical inheritance
This is the type of inheritance in which there are multiple classes derived from one base class. This type of inheritance is used when there is a requirement of one class feature that is needed in multiple classes.
9
Hierarchical inheritance(Exmple)
10
Multilevel inheritance
When one class is derived from another derived class then this type of inheritance is called multilevel inheritance.
11
Multilevel inheritance
12
Multiple inheritance using Interfaces
C# does not support multiple inheritances of classes. To overcome this problem we can use interfaces, we will see more about interfaces in my next article in detail.
13
Multiple inheritance using Interfaces (Example)
14
Constructor in Inheritance
Constructors in a base class are not inherited in a derived class. A derived class has a base portion and derived portion. The base portion initializes the base portion, and the constructor of the derived class initializes the derived portion. Accessibility modifier classname(parameterlist1) : base(parameterlist2) { body } So the base keyword refers to the base class constructor, while parameterlist2 determines which overloaded base class constructor is called.
15
Constructor in Inheritance (Example)
16
Virtual Methods By declaring a base class function as virtual, you allow the function to be overridden in any derived class. The idea behind a virtual function is to redefine the implementation of the base class method in the derived class as required. If a method is virtual in the base class then we have to provide the override keyword in the derived class. Neither member fields nor static functions can be declared as virtual.
17
Virtual Methods
18
Function Overloading Function overloading allows multiple implementations of the same function in a class. Overloaded methods share the same name but have a unique signature. The number of parameters, types of parameters or both must be different. A function can't be overloaded on the basis of a different return type alone.
19
Function Overloading(Example)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.