- 1
Cstrctor Dstrctor I need help
Drag and drop from the options below to declare a ''B'' class with its own constructor and a ''D'' class with its own constructor, where ''D'' inherits ''B''. _____B { public: _____() { cout << "B's constructor"; } }; class D : ______ B { _____() { cout << "D's constructor"; } }; a.B b.this c.public d.class e.D f. protected
6 Answers
+ 1
class B {
public:
B() {
cout << "B's constructor";
}
};
class D: public B {
D() {
cout << "D's constructor";
}
};
The class B has a constructor, which is a method without return type which has the name of the class. This method can be overload.
class D, publicly inherit from class B.
Same thing for the constructor.
+ 1
Xavier Heugue Why publicly and not protectedly?
0
This has not a definite answer. D can inherit from B publicly or protectedly, there is nothing stopping it.
0
It depends if the visibility is needed outside the namespace, but by default, publicly because we want to see the parent's methods
0
thanks all your hue support
0