C++ में inheritance क्या होता है?

C++ में inheritance क्या होता है?

C++ में inheritance क्या होता है?
Ganesh
Friday 3 March 2017
Inheritance-
C++ में किसी function या data type को reuse किया जा सकता है, जिससे उसे दुबारा create करने की आवश्यकता ना पड़े।
C++

C++ में एक class बनाने पर अगर उस class के data type या function को access करना हो तो एक new class का निर्माण करना होता है।
★ Old class से new class को derive करना inheritance कहलाता है।
●Old class को base class या super class कहते है तथा derived class या sub class properties को inherit करती है, 
● Inheritance को use करने के लिए colon
(:) operator का इस्तेमाल होता है।
Class B : A
किसी class को inherit करने के लिए Public या Private mode का इस्तेमाल भी किया जा सकता है, Default mode Private होता है।

C++


Example of inheritance:-
class A
{
int a,b,c,d;
void sum()
{
Court<<"enter the number";
Cin>>a>>b;
C=a+b;
Court<<c;
}
class B : Public A
{
void subtract()
{
d=c-a;
Cout<<a;
}
main()
{
A a1;
B b1;
a1.sum();
b1.subtract();
}
}
}


Open Comments
Close comment

4 comments