Inheritance
The Slide Covers :
What is Inheritance
Types Of Inheritance
Public, Private, Protected
What is Inheritance
The mechanism of deriving a new class from an old one is called inheritance or derivation.
Definition of Inheritance:
Inheritance is the mechanism which allows a class A to inherit properties of a class B.
Inheritance----------------------------------------- Next Slide------------------------------- Hardeep Singh
Types of Inheritance:
Single inheritance
Multiple inheritance
Inheritance----------------------------------------- Next Slide------------------------------- Hardeep Singh
Hierachical Inheritance:
Multilevel Inheritance:
Inheritance----------------------------------------- Next Slide------------------------------- Hardeep Singh
Hybrid Inheritance:
Inheritance----------------------------------------- Next Slide------------------------------- Hardeep Singh
Advantages of Inheritance:
The major advantage is the reusability. Once a base class is written and debugged,it need not be touched again,but can be used to work in different.
It also reduces the frustration in complex programming.
Reusing exiting code saves time.
Inheritance----------------------------------------- Next Slide------------------------------- Hardeep Singh
Disadvantages of Inheritance:
The larger the inheritance model gets, the “wider” the mapped table table gets, in that for every field in the entire inheritance hiearchy, a column must exit in the mapped table.
Inheritance----------------------------------------- Next Slide------------------------------- Hardeep Singh
Private, Public, Protected :
Public:
Exp: class A
{
Public:
Int x;
Private:
Int y;
};
Class B : public A
{
Private:
Int p;
}
Inheritance----------------------------------------- Next Slide------------------------------- Hardeep Singh
Private, Public, Protected :
Inheritance----------------------------------------- Next Slide------------------------------- Hardeep Singh
Private Inheritance :
Exp:class a
{
Private:
Int x;
Public:
Int y; };
Class B : private A
{
Int p; };
Inheritance----------------------------------------- Next Slide------------------------------- Hardeep Singh
Protected :
Exp:
Class A : protected B
{
Private : int X;
};
Inheritance----------------------------------------- Next Slide------------------------------- Hardeep Singh
Abstract class
An abstract class is one that is not used to create objects.an abstract class is used only for base class.
1. What is inheritance in computer science engineering? |
2. How does inheritance improve code reuse in computer science engineering? |
3. What are the types of inheritance in computer science engineering? |
4. What is the significance of protected access specifier in inheritance? |
5. How does inheritance contribute to polymorphism in computer science engineering? |
|
Explore Courses for Computer Science Engineering (CSE) exam
|