- 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

10th Oct 2018, 9:22 AM
Harrison Jao
Harrison Jao - avatar
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.
10th Oct 2018, 10:08 AM
Xavier Heugue
Xavier Heugue - avatar
+ 1
Xavier Heugue Why publicly and not protectedly?
10th Oct 2018, 10:36 AM
Bebida Roja
Bebida Roja - avatar
0
This has not a definite answer. D can inherit from B publicly or protectedly, there is nothing stopping it.
10th Oct 2018, 9:31 AM
Bebida Roja
Bebida Roja - avatar
0
It depends if the visibility is needed outside the namespace, but by default, publicly because we want to see the parent's methods
10th Oct 2018, 7:57 PM
Xavier Heugue
Xavier Heugue - avatar
0
thanks all your hue support
4th Jun 2020, 4:43 AM
Waled Moumari
Waled Moumari - avatar
0
18th Sep 2022, 9:50 PM
Brmj Brmj
Brmj Brmj - avatar