Inheritance: Extending Classes
Inheritance:
- In C++, inheritance is the mechanism by which one class can inherit the properties of another.
- When one class is inherited by another, the class that is inherited is called the base class. The inheriting class is called derived class.
- Base class is also known as parent class or old class. Derived class is also known as child class or new class.
- Remember constructor never inherits.
- Structure in C++ also supports inheritance.
Syntax for
inheritance
class base-name
{
…
…
};
class derived-name :
visibility mode base-name
{
…
…
};
- Syntax covers two classes, one is base class and other is derived class.
- During derived class definition, notice a colon (:) followed by visibility mode and then comes base class name. This addition to derived class definition tells the compiler about linking between two classes.
- Members of base class now also consider members of derived class.
- Membership category for the base class members in derived class are defined by visibility mode.
- Visibility modes are private, protected and public.
- In class, when no visibility mode is mentioned, it is private by default.
- In structure, when no visibility mode is mentioned, it is public by default.
Visibility Modes
- Whatever may the visibility mode, private members of base class never inherits.
- When visibility mode is private, all protected and public members of base class become private members of derived class.
- When visibility mode is protected, all protected and public members of base class become protected members of derived class.
- When visibility mode is public, all protected members of base class become protected members of derived class and all public members of base class become public members of derived class.
- Coming Soon More Updates.
How to use Inhertance in C++ Inheritance in Cpp Inheritance in C plus plus
How to use Inhertance in C++ Inheritance in Cpp Inheritance in C plus plus
How to use Inhertance in C++ Inheritance in Cpp Inheritance in C plus plus
How to use Inhertance in C++ Inheritance in Cpp Inheritance in C plus plus
How to use Inhertance in C++ Inheritance in Cpp Inheritance in C plus plus
How to use Inhertance in C++ Inheritance in Cpp Inheritance in C plus plus
How to use Inhertance in C++ Inheritance in Cpp Inheritance in C plus plus
how to use inheritance in c++
ReplyDeleteHow to use inheritance in cpp
How to use inheritance in c plus plus
how to use inheritance in c++
How to use inheritance in cpp
How to use inheritance in c plus plus
how to use inheritance in c++
How to use inheritance in cpp
How to use inheritance in c plus plus
This comment has been removed by the author.
ReplyDelete