Oop-Unit - 1 &2 Mcq-Question-Bank
Oop-Unit - 1 &2 Mcq-Question-Bank
(2019- Pattern)
Unit I
Sr. No Questions Marks Correct
Answer
1 Every class has at least one constructor function, even when none 1 A
is declared. A) True B) False
2 Can constructors be overloaded? A) True B) False 1 A
3 What is the difference between struct and class in terms of 1 C
Access Modifier?
A. By default all the struct members are private while by
default class members are public.
B. By default all the struct members are protected while by
default class members are private.
C. By default all the struct members are public while by
default class members are private
D. By default all the struct members are public while by
default class members are protected
4 The default access level assigned to members of a class is 1 B
A. Public B. Private C. Protected D. Needs to be assigned
5 1 A
6 Which of the following operators allow defining the member 1 A
functions of a class outside the class?
A. Scope Resolution(: : ) B. (Dpt) Operator C. Conditional
operator D. Dereferencing Operator(->)
7 Which type of class has only one unique value for all the objects 1 A
of that same class?
A. Static B. Friend C. Abstract D. Both A and B
8 What is a constructor? 1 C
A. A class automatically called whenever a new object of
this class is created
B. A class automatically called whenever a new object of
this class is destroyed
C. A function automatically called whenever a new object of
this class is created.
D. A function automatically called whenever a new object of
this class is destroyed.
9 Under what conditions a destructor destroys an object? 1 D
A Scope of existence has finished B. Object dynamically
assigned and it is released using the operator delete. C. Program
terminated. D. All of the above
10 If a member needs to have same value for all the objects of that 1 A
same class, declare the member as
A. Static B. Void C. Friend D. Constant
11 Variables declared in the body of a particular member function 1 B
are known as data members and can be used in all member
A.
A . True B. False
12 In a class definition, data or functions designated private are 1 C0
accessible
A. to any function in the program.
B. only if you know the password.
C. To member functions of that class.
D. Only to public members of the class.
13 Dividing a program into functions 1 D
A. is the key to object-oriented programming.
B. makes the program easier to conceptualize.
C. may reduce the size of the program.
D. Option B and C
14 A function argument is 1 C
A. a variable in the function that receives a value from the
calling program.
B. a way that functions resist accepting the calling program’s
values.
C. a value sent to the function by the calling program.
D. a value returned by the function to the calling program.
15 When arguments are passed by value, the function works with the 1 B
original arguments in the calling program. A. True B. False
16 How many values can be returned from a function? 1 B
A. 0 B.1 C. 2 D. 3
17 What is the Value of size? 2 C
A. 28 B. 32 C. 20 D. 24
18 What will be the output of the program? 2 C
A. 1 B. Default Value C.Compiler Error D. None of the
above
19 What is the output of the program? 2
#include <iostream>
using namespace std;
class Test
{
public:
Test() { cout <<"Hello from Test() "; }
} a;
int main()
{
cout <<"Main Started ";
return 0;
}
A. Main Started
B. Main Started Hello from Test()
C. Hello from Test() Main Started
D. Compiler Error: Global objects are not allowed
25 In C++...................... operator is used for Dynamic memory 1 A
allocation. A. :: B. new C. Membership (Dot Operator)
E. Conditional ?:
26 Which of the following header file includes definition of cin and 1 D
cout?
A. istream.h B. ostream.h C. iomanip D. iostream
27 cout is a/an 1 C
A. operator B. function C. Object 4. Dariable
28 ......... is a member function with the same name as the class. 1 B
A. Friend function B. Constructor
C. Destructor D.None of the above
29 Which is not the feature of constructor? 1 B
A. It cannot be inherited. B. It should be declared in Private.
C. It do n1ot have return type D. All of above
30 Which is not type of constructor? 1 D
A. Default B. Copy C. Parameterized D. None of the above
31 Objects are destroyed in the reverse order of its creation. A. True 1 A
B. False
32 .... constructor is used for copying the object of same class type. 1 B
A. Default B. Copy C. Parameterized D. None of the above
33 The function inside a class is called as ....... 1 B
A. Friend function B. Member Function C. Class Function D. All
of the above
34 How many objects can be created by a class? 1 D
A. 1 B. 2 C. 3. D. Any Number .
35 Default return type of C++ main( ) is ..... 1 B
A. float B. int C. void D. pointer
36 Enumerated data type is ........ 1 A
A. User-defined data type B. Built-In/ Fundamental data type
C. Derived data yype D. All of the above
37 Object-oriented programming follows Top-down approach. 1 B
A. True B. False
38 Which type is best suited to represent the logical values? 1 B
A. Integer B. boolean C. character D. All
39 Inline functions are 1 B
A. Declared in the class defined outside the class
B. Defined outside the class using keyword inline
C. Defined inside the class using keyword inline
D. None of the above
40 Which of the following functions are performed by a constructor? 1 D
A. Construct a new class B. Construct a new object
C. Construct a new function D. Initialize objects
41 What will be the ouput of following : 2 B
#include <stdio.h>
using namespace std;
int array1[] = {1200, 200, 2300, 1230, 1543};
int array2[] = {12, 14, 16, 18, 20};
int temp, result = 0;
int main()
{
for (temp = 0; temp <5; temp++) {
result += array1[temp];
}
for (temp = 0; temp <4; temp++) {
result += array2[temp];
}
cout <<result;
return 0;
}
A. 6553 B. 6533 C. 6522 C. 12200
42 In procedural programming the focus in on …........... 1 B
A. Data B. Function C. Structure D. Pointers
43 In object oriented programming the focus major is on …....... 1 A
A. Data B. Function C. Structure D. Pointers
44 Which of the following data type does not return anything? 1 D
A. int B. short C. long D. void
45 Which of the following statements is correct for a static member 1 C
function?
1. It can access only other static members of its class.
2. It can be called using the class name, instead of objects
A. Only 1 is correct B. Only 2 is correct C. Both 1 and 2 are
correct C. Both 1 and 2 are incorrect
46 When a copy constructor may be called? 1 D
A. When an object of the class is returned by value B. When an
object of the class is passed (to a function) by value as an
argument C. When an object is constructed based on another
object of the same class D. All
47 Output of following program? 2 A
#include<iostream>
using namespace std;
class Point {
Point() { cout <<"Constructor called"; }
};
int main()
{
Point t1;
return 0;
}
int main()
{
Point t1,t2;
return 0;
}
A. Constructor called B. Constructor called Constructor called
C. Compiler Error D. Nothing
#include<iostream>
using namespace std;
class X
{
public:
int x;
};
int main()
{
X a = {10};
cout <<a.x <<" ";
return 0;
}
A. 10 followed by Garbage Value B. 10 C. Compiler Error D. 0
50 Identify the correct sentence regarding inequality between 1 A
reference and pointer.
A. we can not create the array of reference.
B. we can create the array of reference.
C. we can use reference to reference.
None
51 The mechanism that binds code and data together and keeps them 1 C
secure from outside world is known as
A. Polymorphism B. Inheritance C. Encapsulation D. Abstraction
52 Member functions, when defined within the class specification 1 A
A. Are always inline B. Are not inline C. Are inline by default,
unless they are too big or too complicated D. Are not inline by
default.
53 When the compiler cannot differentiate between two overloaded 1 C
constructors, they are called
A. Overloaded B. Destructed C. Ambiguous D. Audacious
54 In which case is it mandatory to provide a destructor in a class? 1 D
A. Almost in every class B. Class for which two or more than
two objects will be created C. Class for which copy constructor is
defined D. Class whose objects will be created dynamically
55 Another term for is data hiding. 1 A
A. Encapsulation B. Abstraction C. Privacy D. None of the above
56 The term refers to a way of organizing classes that 1 D
share properties.
A. Object-oriented B. encapsulation C. Polymorphism D.
Inheritance
57 Encapsulation makes it easier to 1 C
A reuse and modify existing modules of code
B. write and read code by sharing method names.
C. hide and protect data from external code.
D. Both a and b.
58 Inheritance makes it easier to: 1 A
A reuse and modify existing modules of code
B. write and read code by sharing method names.
C. hide and protect data from external code.
D. Both a and b.
59 Which of the following is a C++ object? 1 A
A. cin B. >> C. iostream D. read()
60 Which of the following is the insertion operator? 1 B
A. >> B<< C. : : D. .
61 The term instantiation refers to the creation of: 1 B
A. Class B. Object C. method D. attribute
62 If you declare two objects as Customer firstCust, secondCust; 1 C
which of the following must be true?
A. Each object's non static data members will be stored in the
same memory location
B. Each object will be stored in the same memory location
C. Each object will have a unique memory address
D. You cannot declare two objects of the same class
63 A static data member is initialized with a value 1 B
A. within the class definition.
B. outside the class definition
C. when the program is executed
D. never
64 If you want only one memory location to be reserved for a class 1 A
variable, no matter how many objects are instantiated, you should
declare the variable as
A. static B. inline C. volatile D. dynamic
65 The operator that releases previously allocated memory is 1 C
A. release B. return C. delete D. destroy
66 The new operator 1 C
A. returns a pointer to the variable
B. creates a variable called new
C. obtains memory for a new variable
D. tells how much memory is available
67 A class defined within another class is: 1 A
A. Nested class B. Local Class C. Containership D.
Encapsulation
68 Constructors never have explicit return type A. True B. False 1 A
69 Can I Inherit constructor and destructor of a base class ? A. Yes 1 B
B. No
70 Given a class named Book, which of the following is not a valid 1 C
constructor?
A. Book ( ) { }
B. Book ( Book &b){ }
C. Book ( Book b) { }
D. Book (char* author, char* title) { }
71 Which value we cannot assign to reference? 1 D
A. int B. float C. unsigned D. null
72 #include <iostream> 2 A
using namespace std;
int main()
{
int x;
int *p;
x = 5;
p = &x;
cout << *p;
return 0;
}
A. 5 B. 10 C. Memory Address D. None
OOP Question Bank for Final Theory Exam
(2019- Pattern)
Unit-II
Sr. Questions Marks Correct
No Answer
1 The keyword friend appear in 1 C
A. private section of the class B. public section of the class C. Both
A and B D. None of the above
2 It is possible to declare as a friend 1 D
A. A member function B. A global function C. A class D. All of the
above
3 A friend function to a class, C cannot access 1 D
A. Private data members and member functions
B. Public data members and member functions
C. Protected data members and member functions
D. The data members of the derived class of C
4 Which of the following declarations are illegal? 1 C
A. void *ptr; B char *str=”hello”; C. char str=”hello” D. const *char
c;
5 Identify the operator that is NOT used with pointers 1 D
A & B * C -> D. >>
6 Which statement is true? 1 D
A. A base class inherits some of the properties of a derived class.
B. A base class inherits all of the properties of a derived class.
C. A derived class inherits some of the properties of a base class.
D. A derived class inherits all of the properties of a base class.
7 A pointer to the base class can hold address of 1 C
A. only base class object
B. only derived class object
C. base class object as well as derived class object
D. None of the above
8 When class B is inherited from class A, what is the order in which 1 A
the constructers of those classes are called
A. Class A first Class B next
B. Class B first Class A next
C. Class B's only as it is the child class
D. Class A's only as it is the parent class
9 C++ does not supports the following 1 D
A. Multiple Inheritance B. Multilevel C. Hierarchical D. None of
the above
10 The main intention of using inheritance is …......... 1 C
A. to help in converting one data type to other
B. to hide the details of base class
C. to extend the capabilities of base class
D. to help in modular programming
11 Is it fine to call delete twice for a pointer? 1 B
#include<iostream>
using namespace std;
int main()
{
int *ptr = new int;
delete ptr;
delete ptr;
return 0;
}
A. Yes B. No
12 Derived Derived A. Polymorphism B. Message passing C. 1 C
Inheritance D. Operator Overloading
#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;
}
#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
32 What is the output of the following program? {Assume size of int as 2 A
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;
}
33 What will be the output of the following program? 2 D
#include<iostream>
using namespace std;
class Base { public:
Base() { cout <<"Base Ctor "; }
~Base() { cout <<"Base Dtor "; }
};
class Derived: public Base { public:
Derived() { cout <<"Derived Ctor "; }
~Derived() { cout <<"Derived Dtor "; }
};
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
34 What will be the output of the program? 2 B
#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
35 What will be the output of the program? 2 B
#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 mentioned
36 When deriving a class from with protected inheritance, public 1 A
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
37 When deriving a class with public inheritance, public members of 1 B
the base class become members of the derived class,
and protected members of the base class become
members of the derived class.
A. private, private B. public, protected. C. protected, protected D.
Private, protected
38 Which of the following is true about this pointer? 1 B
A. It is passed as a hidden argument to all function calls
B. It is passed as a hidden argument to all non-static function calls
C. It is passed as a hidden argument to all static functions
D. None of the above
39 The inheritance is described as a relationship 1 B
A. has a B. is a C. association D. None of these
40 When the object of derived class expire, first the is 1 B
invoked followed by the .
A. derived class constructor, base class destructor
B. derived class destructor , base class destructor
C. base class destructor , derived class destructor
D. none of these
41 If class A is a friend class of class B, if class B is friend class of 1 C
class C then
A. class C is friend class of A
B. class A is friend class of C
C. class A and class C do not have any friendship relation.
D. none of these
42 When base class pointer points to derived class object 1 A
A. it can access only base class members
B. it can access only derived class members
C. both base class &derived class members
D. None of these
43 What will happen on execution of the following code ? 1 C
Class base
{
};class derived: protected base
{
};
A. It will not compile as the class body of the base class is not
defined
B. It will not compile as the class body of the derived class is not
defined
C. It will compile successfully
D. The compilation of above code is dependent upon the type of
data provided to it
44 How many types of inheritance are there 1 D
A. 2 B. 3 C. 4 D.5
45 Suppose class derived is derived from a class Base. Both the classes 1 C
contain the Function name display() that take no argument. What
will be the statement in the class derived which will called the
display function of base class
A. display() B. Base:display() C. Base ::display() D. Cannot make
such a call
46 Suppose class derived is derived from a class Base privately. The 1 D
object of class Derived is located in main() can access .
A. public members of base B. private members of base
C. protected members of base
D. public members of derived
47 Which is the correct class definition for class C ,Which inherits 1 C
from A &B classes
A. Class C:A,B B. Class C::A,B C. Class C:public A,public B
D. Class C::public A,public B
48 What does the following statement mean? 1 C
int (*fp)(char*)
A. pointer to a pointer
B. pointer to an array of chars
C. pointer to function taking a char* argument and returns an int
D. function taking a char* argument and returning a pointer to int
49 The operator used for dereferencing or indirection is 1 A
A. * B. & C. -> D. ->>
50 Choose the right option 1 A
string* x, y;
A. x is a pointer to a string, y is a string
B. y is a pointer to a string, x is a string
C. both x and y are pointer to string types
D. both x and y are string types
51 #include <iostream> 1 D
using namespace std;
int main()
{
int a = 5, b = 10, c = 15;
int *arr[ ] = {&a, &b, &c};
cout <<arr[1];
return 0;
}
A. 10 B. 15 C. 20 D. Random number
52 The correct statement for a function that takes pointer to a float, a 1 C
pointer to a pointer to a char and returns a pointer to a pointer to a
integer is
A. int **fun(float**, char**)
B. int *fun(float*, char*)
C. int ***fun(float*, char**)
D. int ***fun(*float, **char)
53 #include <iostream> 2 A
using namespace std;
int main()
{
char arr[20];
int i;
for(i = 0; i < 10; i++)
*(arr + i) = 65 + i;
*(arr + i) = '\0';
cout << arr;
return(0);
}
A. ABCDEFGHIJ
B. AAAAAAAAA
C. JJJJJJJJJJJJ
D. None
54 #include <iostream> 2 A
using namespace std;
int main()
{
char *ptr;
char Str[] = "abcdefg";
ptr = Str;
ptr += 5;
cout << ptr;
return 0;
}
A. fg B. cdef C. defg D. abcd
55 #include <iostream> 2 D
using namespace std;
class Box
{
double width;
public:
friend void printWidth( Box box );
void setWidth( double wid );
};
void Box::setWidth( double wid )
{
width = wid;
}
void printWidth( Box box )
{
box.width = box.width * 2;
cout << "Width of box : " << box.width << endl;
}
int main( )
{
Box box;
box.setWidth(10.0);
printWidth( box );
return 0;
}
A. Width of box : 40 B. Width of box : 5 C. Width of box : 10
D. Width of box : 20
56 #include <iostream> 2 C
using namespace std;
class sample
{
private:
int a, b;
public:
void test()
{
a = 100;
b = 200;
}
friend int compute(sample e1);
};
int compute(sample e1)
{
return int(e1.a + e1.b) - 5;
}
int main()
{
sample e;
e.test();
cout << compute(e);
return 0;
}
A. 100 B. 200 C. 295 D. 395
57 2 A
#include <iostream>
using namespace std;
class base
{
int val1, val2;
public:
int get()
{
val1 = 100;
val2 = 300;
}
friend float mean(base ob);
};
float mean(base ob)
{
return float(ob.val1 + ob.val2) / 2;
}
int main()
{
base obj;
obj.get();
cout << mean(obj);
return 0;
}