OOPSMCQGoogleDocs-coding Blocks
OOPSMCQGoogleDocs-coding Blocks
OOPS MCQ
Q1 Which of the following in Object Oriented Programming is supported by
Function overloading and default arguments features of C++?
A) Inheritance
B) Abstraction
C) Polymorphism
D) Abstraction
Q2 Which of the following is incorrect with respect to constructors in C++?
A) A constructor can call member function of its class.
B) If the default constructor is defined explicitly then, compiler will not
define the constructor implicitly, it calls the constructor implicitly.
C) A constructor cannot dynamically allocate for an object at the time of
their construction.
D) These cannot be static
Q3 Predict the output?
#include <iostream> using namespace std;
class Test {
int x; Test() {
x = 5;
}
};
int main() {
Test *t = new Test;
cout << t>x;
}
A) 0
B) 5
C) Garbage value
D) Compiler error
Q4 Which of the following is correct for virtual function in C++ ? (More than
one)
a) Must be declared in public section of class.
b) Virtual function can be static.
c) Virtual function should be accessed using pointers.
d) Virtual function is defined in base class.
Q5 Multiple inheritance leaves room for a derived class to have _______
members.
A) Dynamic
B) Private
C) Public
D) Ambiguous
Q6 What makes a class abstract?
A) The class must not have method definitions.
B) The class must have a constructor that takes no arguments.
C) The class must have a function definition equal to zero.
D) The class which cannot be instantiated as they are mainly for
inheritance.
Q7 When two or more classes serve as base class for a derived class, the
situation is known as __________.
A) multiple inheritance
B) Inheritance
C) Encapsulation
D) hierarchical inheritance
Q8 __________ allows for the separation of object interactions from
classes and inheritance into distinct layers of abstraction
A) Dispatching
B) Loosening
C) Detaching
D) Decoupling
Q9 What is the use of parametric polymorphism?(more than one)
A) A function or a data type can be written generically so that it can
handle values identically without depending on their type
B) A function or a data type can be written generically so that it can
handle values identically being dependant on their type
C) A function or a data type that can accept parameters
D) Both a and c
Q10 Which of the following is false for friend function?
A) Allows access to private or protected data in a class from outside
the class
B) both a and c
C) Too many friend functions may hamper data security
D) When a function needs to operate on private data in objects from
two different classes, the function can be declared as a friend in any
of the classes
Q11 The ____________ functions of the base class are also not inherited
A) friend
B) Pure virtual function
C) Both a and b
D) Virtual function
Q12 ______________ is actually a parameterized constructor which takes
some parameters in order to create instance of a class.
A) Implicit constructor
B) Explicit constructor
C) Virtual constructor
D) Parameterized constructor
Q13 Which of the following is false for a destructor?
A) The destructor has the same name as the class
B) If the object was created with a new expression, then its destructor is
called when the delete operator is applied to a pointer to the object
C) Its main purpose is to clean up and to free the resources
D) none
Q14 Which of the following is true about virtual functions in C++.
A) Virtual functions are functions that can be overridden in derived
class with the same signature.
B) Virtual functions enable runtime polymorphism in a inheritance
hierarchy.
C) If a function is 'virtual' in the base class, the mostderived class's
implementation of the function is called according to the actual type of
the object referred to, regardless of the declared type of the pointer or
reference. In nonvirtual functions, the functions are called according
to the type of reference or pointer.
D) All of the above
Q15 Which of the following are true about static member function?
1) They can access nonstatic data members
2) They can call only other static member functions
3) They can access global functions and data
4) They can have this pointer
5) They cannot be declared as const or volatile
Q16 Which of the following is the correct class of the object cout?
A) iostream
B) Istream
C) Ostream
D) ifstream
Q17 Which of the following problem causes an exception?
A) Missing semicolon in statement in main().
B) A problem in calling function
C) A syntax error
D) A runtime error