Possible Duplicate:
What are access specifiers? Should I inherit with private, protected or public?
Difference between private, public and protected inheritance in C++
To all you cpp experts, In c++ inheritance,
class B : public A {
};
I am just curious why is the keyword public needed here? Does it mean something?
Correct choice is (c) class derived_classname : access base_classname{ /*define class body*/ }; The explanation is: Firstly, keyword class should come, followed by the derived class name.
Master C and Embedded C Programming- Learn as you go So the class can inherit features from multiple base classes using multiple inheritance. This is an important feature of object oriented programming languages such as C++.
Syntax of Implementing Multiple Inheritance in C++ Description of the syntax: access_modifier: It provides the access modifier in the class declaration as it specifies how the derived class is inheriting the base class. base_class: There can be over one base class, from which the derived class inherits its properties.
The Syntax for Inheritance in C++The keyword class: Just like defining any usual class in C++, which requires a keyword class, defining a subclass also follows a similar syntax. Name of the subclass: You have to specify the name of the sub-class or the derived class that inherits the properties of some other class.
It means public
members in A
are inherited by B
and are also public from B
.
The alternatives are:
protected - public members from A
are made protected in B
, others are kept the same.
private - all members from A
are made private in B
.
The rules don't apply to methods that are hidden or overriden.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With