Try new tool: URL Shortener

https://res.cloudinary.com/hg6hswtwo/image/upload/v1/media/pics/oop_toolsandjobs_se2jyx_pppjrl
secondyear

Polymorphism & Inheritance MCQs in OOP For Exams Part 3





Polymorphism & Inheritance MCQs in OOP For Exams Part 3. Objective questions most helps in SPPU exams 2020-21 and other exams.

click here for Part-2 Mcq

1 Make a correct sequence of a statement
i)destructor of derived class is called
ii)destructor of base class is called
iii)constructor of derived class is called
iv)constructor of base class is called
A i,ii,iv,iii
B iv,iii,ii,i
C iv,iii,i,ii
D i,ii,iii,iv

Answer C

2 Operator overloading is
A making C++ operators work with objects.
B giving C++ operators more than they can handle.
C giving new meanings to existing C++ operators.
D Both A and C

Answer D

3 Assume a class C with objects obj1, obj2, and obj3. For the statement obj3 = obj1 - obj2
to work correctly, the overloaded - operator must
A take two arguments.
B return a value.
C use the object of which it is a member as an operand.
D Both B and C

Answer D

4 When you overload an arithmetic assignment operator, the result
A goes in the object to the right of the operator.
B goes in the object to the left of the operator.
C goes in the object of which the operator is a member.
D Both B and C
Answer D

5 To convert from a user-defined class to a basic type, you would most likely use
A a built-in conversion operator.
B a one-argument constructor.
C an overloaded = operator.
D a conversion operator that’s a member of the class.

Answer D

6 An overloaded operator always requires one less argument than its number
of operands.
A TRUE
B FALSE

Answer A 

7 The compiler won’t object if you overload the * operator to perform division.
A TRUE
B FALSE

Answer A

8 Inheritance is a way to
A make general classes into more specific classes.
B pass arguments to objects of classes.
C add features to existing classes without rewriting them.
D A and C

Answer D

9 Advantages of inheritance include
A providing a useful conceptual framework.
B facilitating class libraries.
C avoiding the rewriting of code.
D All of the above
Answer D

10 Adding a derived class to a base class requires fundamental changes to the base class.
A TRUE
B FALSE

Answer D

11 To be accessed from a member function of the derived class, data or functions in the base
class must be
A public
B private
C protected
D static

Answer C

12 If a base class contains a member function basefunc(), and a derived class does not
contain a function with this name, can an object of the derived class access basefunc()?
A YES
B NO

Answer A

13 If no constructors are specified for a derived class, objects of the derived class will use the
constructors in the base class.
A TRUE
B FALSE

Answer A

14 The scope-resolution operator usually
A specifies a particular class.
B tells what base class a class is derived from.
C resolves ambiguities.
D A and C

Answer D

15 Assume a class Derv that is privately derived from class Base. An object of class Derv
located in main() can access
A public members of Derv.
B protected members of Derv.
C private members of Derv.
D public members of Base.

Answer A

16 True or False: A class Dcan be derived from a class C, which is derived from a class B,
which is derived from a class A.
A TRUE
B FALSE

Answer A

17 It is illegal to make objects of one class members of another class.
A TRUE
B FALSE

Answer B

18 A class hierarchy
A shows the same relationships as an organization chart.
B describes “has a” relationships.
C describes “is a kind of” relationships.
D shows the same relationships as a family tree.

Answer C

19 What is the output of the program?
#include <iostream>
#include <string>
using namespace std;
class Department {
public:
string dept;
Department(string d):dept(d) { }
void getDeptName() { cout <<dept; }
};
class Student : private Department {
public:
string name;
Student(string n = "Not entered", string d = "ATDC") :
name(n), Department(d) { }
using Department::getDeptName;
};
int main() {
Student s("CSE");
s.getDeptName();
return 0;
}
A CSE
B ATDC
C Not entered
D Compilation Error

Answer B

20 Identify the lines on which the compiler will report an error.
#include <iostream>// ---1
using namespace std; // ---2
class Base { // ---3
int var_; // ---4
public: // ---5
Base():var_(0){} // ---6
}; // ---7
class Derived: public Base { public: // ---8
int varD_; // ---9
void print () { cout <<var_; } // ---10
}; // ---11
int main() { // ---12
Derived d; // ---13
d.var_ = 1; // ---14
d.varD_ = 1; // ---15
cout <<d.var_ <<""<<d.varD_; // ---16
return 0; // ---17
} // ---18
A 6, 10, 14, 15
B 6, 15
C 6, 14, 16
D 10, 14, 16

Answer D

21 #include <iostream>
using namespace std;
class Base { public:
int var_;
void func(int){}
};
class Derived: public Base { public:
int varD_;
void func(int){}
};
int main() {
Derived d;
d.func(1);
return 0;
}
Which of the following function will be invoked by d.func(1)?
A Base::func(int)
B Derived::func(int)
C Compilation Error
D None of the above
 

Answer B

22 What is the output of the following program?
#include<iostream>
#include<string>
using namespace std;
class Base {
public:
void func_f1(int i) { cout <<"In base func_f1 "; }
void func_f2(int i) { cout <<"In base func_f2 "; }
};
class Derived: public Base {
public:
void func_f1(int i ) { cout <<"In derived func_f1 "; }
void func_f1(string s) { cout <<"func_f1 string "; }
void func_f3(int i) { cout <<"In derived func_f3 "; }
};
int main() {
Base b;
Derived d;
d.func_f1(3);
d.func_f1("Blue");
d.func_f3(3);
d.func_f2(3);
return 0;
}
A Compilation Error: Cannot add new parameters to func_f1
B In derived func_f1 func_f1 string In derived func_f3 In base func_f2
C In base func_f2 func_f1 string In derived func_f3 In derived func_f1
D Compilation Error: Cannot define func_f3 containing same parameter type as func_f1

Answer B

23 What is the output of the following program? {Assume size of int as 4}
#include<iostream>
using namespace std;
class base {
int data;
};
class derived1: public base { };
class derived2: public derived1 { };
int main() {
cout <<sizeof(derived2);
return 0;
}
A 4
B 8
C 12
D 16

Answer A

24 What will be the output of the following program?
#include <iostream>
using namespace std;
class B{ public: int base;
B() {}
~B() {}
};
class D: public B { public: int derived;
D() {}
~D() {}
};
int main() {
D d1;
B b1;
cout <<&b1.base <<"";
cout <<&d1.base;
return 0;
}
A 0x28fef8 0x28fef8
B 0x28fef8 0x28fefc
C Compilation Error
D None of the above

Answer B

25 What will be the output of the following program?
#include<iostream>
using namespace std;
class Base { public:
Base() { cout <<"Base Ctor"<<endl; }
~Base() { cout <<"Base Dtor"<<endl; }
};
class Derived: public Base { public:
Derived() { cout <<"Derived Ctor"<<endl; }
~Derived() { cout <<"Derived Dtor"<<endl; }
};
int main() {
Derived d1;
{
Base b1;
}
return 0;
}
A Base Ctor
Derived Ctor
Base Ctor
Base Dtor
Base Dtor
Derived Dtor
B Derived Ctor
Base Ctor
Base Ctor
Base Dtor
Derived Dtor
Base Dtor
C Derived Ctor
Base Ctor
Base Dtor
Derived Dtor
D Base Ctor
Derived Ctor
Base Ctor
Base Dtor
Derived Dtor
Base Dtor

Answer D

26 What will be the output of the program?
#include <iostream>
using namespace std;
class F1 {
public:
F1() { cout <<"F1 ctor "; }
~F1() { cout <<"F1 dtor "; }
};
class F2 : public F1 {
public:
F2() { cout <<"F2 ctor "; }
~F2() { cout <<"F2 dtor "; }
};
class F3 : public F1 {
const F2 &f2;
public:
F3() : f2(*new F2) { cout <<"F3 ctor "; }
~F3() { cout <<"F3 dtor "; }
};
int main() {
F3 f3;
return 0;
}
A F1 ctor F2 ctor F3 ctor F3 dtor F2 dtor F1 dtor
B F1 ctor F1 ctor F2 ctor F3 ctor F3 dtor F1 dtor
C F1 ctor F3 ctor F3 dtor F1 dtor
D F1 ctor F1 ctor F2 ctor F3 ctor F3 dtor F2 dtor F1 dtor F1 dtor

Answer B

27 What will be the output of the program?
#include <iostream>
using namespace std;
class Room {
int number;
public:
Room(int num = 0): number(num) { }
void dimension() { cout <<number <<"Rooms "; }
};
class Building {
public:
Building() : ro(100) { }
void Build() { ro.dimension(); }
private:
Room ro;
};
int main() {
Building B;
B.Build();
return 0;
}
A 0 Rooms
B 100 Rooms
C Compilation Error: ro is private
D None of the above

Answer B

28 What will be the output of the program?
#include<iostream>
using namespace std;
class Shape {
public:
int x, y;
Shape(int a = 0, int b = 0): x(a), y(b) {}
void draw()
{ cout <<x <<""<<y <<""; }
};
class Rectangle : public Shape {
public:
int w, h;
Rectangle(int a = 5, int b = 6): w(a), h(b), Shape(7, 8) {}
void draw()
{ Shape::draw(); cout <<w <<""<<h ; }
};
int main() {
Rectangle *r = new Rectangle(1,2);
r->draw();
return 0;
}
A 0 0 1 2
B 7 8 1 2
C 7 8 5 6
D 0 0 5 6

Answer B

29 You cannot change the precedence and associativity of an operator by overloading.
A TRUE
B FALSE

Answer A 

30 When deriving a class from with protected inheritance, public members of the base class
become___________ members of the derived class, and protected members of the
base class become _____________ members of the derived class.
A protected, protected.
B public, private
C private, private
D Private, protected

Answer A

Click here for Part-4





Publish Your Great Work

Your AD here