In C++...
If Class B inherits from Class A, i.e. Class B is a subclass of Class A, Class B would have all of the member data and member functions of Class A without you declaring them. However, the constructor of Class A will not be inherited in Class B.
Class B can of course have extra member data and member functions of it's own and put in it's own declaration.
Depending on the type of inheritance (public, protected, private), it determines the protection level of the inherited members from Class A in Class B.
If public is chosen, all members remain the same protection level in Class B.
If protected is chosen, all members that are public in Class A will be protected in Class B. Others will remain the same.
If private is chosen, all members in Class A will be private in Class B.
Hope this helps. =)
2006-09-10 16:38:29
·
answer #1
·
answered by silverwhiskers 2
·
0⤊
0⤋
Think of inheritance in the sense of a father passing on his fortune to his son. The son then starts out with everything his father had, and then builds on that (we'll just ignore the fact that the governemtn will tax the hell out of it)
It is useful when you will have more than one object that will have the same basic foundation but will differ very slightly. You take the common parts and create a "father" class, then inherit the class to create the two new classes where you define the differences.
For example, in Windows a "button" and a "scroll bar" are both windows objects, they look and work differently but they both have many things in common. For example, they must both accept mouse input, keyboard input, store their state and position on the screen, have a color scheme, etc.
2006-09-10 17:44:52
·
answer #2
·
answered by soulblazer28 2
·
0⤊
0⤋
inheritance is just like real life superclass is like father and subclasses are like children.
A child inherit everything from his father but it can add many things that his father doesn't have
inheritance is for some cases that we have a whole thing that the parts of that whole thing are also classes. for example we have a class school(superclass) which has name, facility, address and we have sublasses like student that they have name,ID,age,etc..without inheritance you can put for each student school name and school facility and these things but inheritance make this easier you just make a superclass and input everything and automatically it will assign to all subclasses it reduce the time user need to input data ...
hope you get the concept if you get it you can easily apply it
2006-09-10 17:34:02
·
answer #3
·
answered by morteza 2
·
0⤊
0⤋