Question: Here is a listing of C++ programming questions on Derived Classes along with answers, explanations and/or solutions: 1. Where is the derived class is derived
Here is a listing of C++ programming questions on "Derived Classes" along with answers, explanations and/or solutions: 1. Where is the derived class is derived from? a) derived b) base c) both derived & base d) class 2. Pick out the correct statement. a) A derived class's constructor cannot explicitly invokes its base class's constructor b) A derived class's destructor cannot invoke its base class's destructor c) A derived class's destructor can invoke its base class's destructor d) A derived class's destructor can invoke its base & derived class's destructor 3. Which of the following can derived class inherit? a) members b) functions c) both members & functions d) classes 4. What will be the output of the following C++ code? #include using namespace std; class A { public: A(int n ) { cout << n; } }; class B: public A { public: B(int n, double d) : A(n) { cout << d; } }; class C: public B { public: C(int n, double d, char ch) : B(n, d) { cout < using namespace std; class BaseClass { protected: int i; public: BaseClass(int x) { i = x; } ~BaseClass() { } }; class DerivedClass: public BaseClass { int j; public: DerivedClass(int x, int y): BaseClass(y) { j = x; } ~DerivedClass() { } void show() { cout << i << " " << j << endl; } }; int main() { DerivedClass ob(3, 4); ob.show(); return 0; } a) 3 4 b) 4 3 c) 4 d) 3 6. What will be the output of the following C++ code? #include using namespace std; class Base { public: int m; Base(int n=0) : m(n) { cout << "Base" << endl; } }; class Derived: public Base { public: double d; Derived(double de = 0.0) : d(de) { cout << "Derived" << endl; } }; int main() { cout << "Instantiating Base" << endl; Base cBase; cout << "Instantiating Derived" << endl; Derived cDerived; return 0; } a) Instantiating Base Base Instantiating Derived Base Derived b) Instantiating Base Instantiating Derived Base Derived c) Instantiating Base Base Instantiating Derived Base d) Instantiating Base
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
