INHERITANCE
Inheritance is basically nothing but property of One Class to inherit properties from another Class.
So, the question arises that how we can do that?
The answer is simple that when you define a Class(i.e. when you make a Class) and then you create another class which can also can access some parts of the Base class then it is considered as Inheritance.
Syntax:
class base class-name{
};
class derived class-name : visibility mode base class-name{
}
Visibility mode can be private, protected or even public. it means which part the derived class can access from the Base Class(i.e. either private or protected or public).
Let's take an Example to understand it better.
Example:
class Base{
//Let's assume that all functions are defined
} ;
class Subclass : public Base
{
};
Now the Subclass will be able to access all the Public members of the Class Base(Either Variables or Functions). If it was protected then the Sub class would be able to access the protected members of Class base.
I will post the next topic soon.If you have any questions you can ask in the Comments.
Thanks.
No comments:
Post a Comment