Question 1 of 25
Hints left: 3
Q1
What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class A { float d; public: virtual void func(){ cout<<"Hello this is class A\n"; } }; class B: public A { int a = 15; public: void func(){ cout<<"Hello this is class B\n"; } }; int main(int argc, char const *argv[]) { A *a; a->func(); return 0; }
Q2
Which design patterns benefit from the multiple inheritances?
Q3
What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class A { int a; public: A(){ a = 0; } void show(){ a++; cout<<"a: "<<a<<endl; } }; class B: private A { public: }; int main(int argc, char const *argv[]) { B b; b.show(); return 0; }
Q4
What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class A { public: virtual A(){ cout<<"A's Constructor\n"; } }; class B: public A { public: A(){ cout<<"Present inside the class B\n"; } }; int main(int argc, char const *argv[]) { A a; return 0; }
Q5
What is a virtual function in C++?
Q6
What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class Mammal { public: virtual void Define(){ cout<<"I'm a Mammal\n"; } }; class Human: public Mammal { public: void Define(){ cout<<"I'm a Human\n"; } }; class Male: public Human { public: void Define(){ cout<<"I'm a Male\n"; } }; class Female: public Human { public: void Define(){ cout<<"I'm a Female\n"; } }; int main(int argc, char const *argv[]) { Mammal *M = new Mammal(); Male m; Female f; *M = m; M->Define(); M = &m; M->Define(); return 0; }
Q7
Pick the correct statement.
Q8
What happens if the following C++ program is compiled? #include <iostream> #include <string> using namespace std; class A { int a; public: A(){ a = 0; } void show(){ a++; cout<<"a: "<<a<<endl; } }; class B: private A { public: void show(){ show(); } }; int main(int argc, char const *argv[]) { B b; b.show(); return 0; }
Q9
What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class A { int a; public: A(){ a = 0; } void show(){ a++; cout<<"a: "<<a<<endl; } }; class B: public A { public: }; int main(int argc, char const *argv[]) { B b; b.show(); return 0; }
Q10
What will be the output of the following C++ code? #include <iostream> using namespace std; class student { public: int rno , m1 , m2 ; void get() { rno = 15, m1 = 10, m2 = 10; } }; class sports { public: int sm; void getsm() { sm = 10; } }; class statement:public student,public sports { int tot,avg; public: void display() { tot = (m1 + m2 + sm); avg = tot / 3; cout << tot; cout << avg; } }; int main() { statement obj; obj.get(); obj.getsm(); obj.display(); }
Q11
What will be the output of the following C++ code? #include <iostream> using namespace std; struct a { int count; }; struct b { int* value; }; struct c : public a, public b { }; int main() { c* p = new c; p->value = 0; cout << "Inherited"; return 0; }
Q12
What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class A { float d; public: virtual void func(){ cout<<"Hello this is class A\n"; } }; class B: public A { int a = 15; public: void func(){ cout<<"Hello this is class B\n"; } }; int main(int argc, char const *argv[]) { A *a = new A(); B b; a = &b; a->func(); return 0; }
Q13
Which of the following advantages we lose by using multiple inheritances?
Q14
What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class Mammal { public: virtual void Define(){ cout<<"I'm a Mammal\n"; } }; class Human: public Mammal { private: void Define(){ cout<<"I'm a Human\n"; } }; int main(int argc, char const *argv[]) { Mammal *M = new Mammal(); Human H; M = &H; M->Define(); return 0; }
Q15
What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class A { int a; public: A(){ a = 0; } static void show(){ a++; cout<<a; } }; class B: public A { public: }; int main(int argc, char const *argv[]) { B b; b.show(); return 0; }
Q16
What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class A { public: virtual static void show(){ cout<<"class A\n"; } }; class B: public A { public: static void show(){ cout<<"class B\n"; } }; int main(int argc, char const *argv[]) { A *a = new A(); B b; a = &b; a->show(); return 0; }
Q17
What is a pure virtual function?
Q18
Which is the correct syntax of declaring a virtual function?
Q19
What is Inheritance in C++?
Q20
What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class A { float d; public: int a; void change(int i){ a = i; } void value_of_a(){ cout<<a; } }; class B: public A { int a = 15; public: void print(){ cout<<a; } }; int main(int argc, char const *argv[]) { B b; b.change(10); b.print(); b.value_of_a(); return 0; }
Q21
What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class A{ float d; public: virtual void func(){ cout<<"Hello this is class A\n"; } }; class B: public A{ int a = 15; public: void func(){ cout<<"Hello this is class B\n"; } }; int main(int argc, char const *argv[]) { B b; b.func(); return 0; }
Q22
What will be the output of the following C++ code? #include <iostream> using namespace std; class Base1 { protected: int SampleDataOne; public: Base1() { SampleDataOne = 100; } ~Base1() { } int SampleFunctOne() { return SampleDataOne; } }; class Base2 { protected: int SampleDataTwo; public: Base2() { SampleDataTwo = 200; } ~Base2() { } int SampleFunctTwo() { return SampleDataTwo; } }; class Derived1 : public Base1, public Base2 { int MyData; public: Derived1() { MyData = 300; } ~Derived1() { } int MyFunct() { return (MyData + SampleDataOne + SampleDataTwo); } }; int main() { Base1 SampleObjOne; Base2 SampleObjTwo; Derived1 SampleObjThree; cout << SampleObjThree.Base1 :: SampleFunctOne() << endl; cout << SampleObjThree.Base2 :: SampleFunctTwo() << endl; return 0; }
Q23
Which statement is incorrect about virtual function.
Q24
What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class A { float d; public: A(){ cout<<"Constructor of class A\n"; } }; class B: public A { int a = 15; public: B(){ cout<<"Constructor of class B\n"; } }; int main(int argc, char const *argv[]) { B b; return 0; }
Q25
What will be the output of the following C++ code? #include <iostream> using namespace std; class Base { public: virtual void print() const = 0; }; class DerivedOne : public Base { public: void print() const { cout << "DerivedOne\n"; } }; class DerivedTwo : public Base { public: void print() const { cout << "DerivedTwo\n"; } }; class Multiple : public DerivedOne, public DerivedTwo { public: void print() const { DerivedTwo :: print(); } }; int main() { int i; Multiple both; DerivedOne one; DerivedTwo two; Base *array[ 3 ]; array[ 0 ] = &both; array[ 1 ] = &one; array[ 2 ] = &two; array[ i ] -> print(); return 0; }