What is Inheritance in C++ ?
Inheritance :- It allows the extension and reuse of existing code with out having to re- write the code. Inheritance involves the creation of new classes from an existing class. New classes are called derived class /new class/child class/ sub-class and existing class is called base class /old class/parent class/ super class. The derive class inherit the members of base class and also add its own.
Example:- class A
{
Int x;
Public:
Void display()
{
Cout <<x;
}
};
Class B : public A
{
Int y;
Public:
Void show()
{
C out <<y;
}
};
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment