100% found this document useful (3 votes)
9K views14 pages

MCQ Oops With C++ Questions With Answer

This document contains 50 multiple choice questions (MCQs) related to object-oriented programming concepts in C++. The questions cover topics like classes, objects, inheritance, polymorphism, templates, constructors, destructors and more. For each question, 4 answer options are provided and only one is correct.

Uploaded by

Tarandeep singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (3 votes)
9K views14 pages

MCQ Oops With C++ Questions With Answer

This document contains 50 multiple choice questions (MCQs) related to object-oriented programming concepts in C++. The questions cover topics like classes, objects, inheritance, polymorphism, templates, constructors, destructors and more. For each question, 4 answer options are provided and only one is correct.

Uploaded by

Tarandeep singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

MCQ OOPS WITH C++

IMPORTANT QUESTIONS WITH ANSWER


UNIT-1 TO UNIT-5

1.Object oriented programming employs_________ programming approach.

a. top-down

b. procedural

c. bottom-up C

d. all of these.
.

Q2 Which of the following statements is incorrect?

A. Friend keyword can be used in the class to allow access to another class.

B. Friend keyword can be used for a function in the public section of a class.

C. Friend keyword can be used for a function in the private section of a class.

D. Friend keyword can be used on main(). D


Q3 _________________are used for generic programming.
a. Inheritance

b. Virtual Functions

c. Templates C

d. None of these

Q4 How can we make a class abstract?

A. By making all member functions constant.

B. By making at least one member function as pure virtual function. B


C. By declaring it abstract using the static keyword.

D. By declaring it abstract using the virtual keyword.

Q5 How many times kumar.com is printed?

int main()
{
while(1)
{
Cout<<"kumar.com"<<endl;
}

return 0;
}

(A) 1 time
(B) Compilation Error
(C) Infinite times c
(D) Runtime Error

Q6 Which of the following access specifies is used in a class definition by default?

A. Protected

B. Public

C. Private C

D. Friend
Q7 Which of the following keywords is used to control access to a class member?

A. Default

B. Break

C. Protected C

D. public
Q8 What is output of below program?

int main()
{
int i,j,count;
count=0;
for(i=0; i<5; i++);
{
for(j=0;j<5;j++);
{
count++;
}
}
printf("%d",count);

return 0;

(A) 55
(B) 54
(C) 1 C
(D) 0

Q9 What does the class definitions in following code represent?

class Bike
{
Engine objEng;
};
class Engine
{
float CC;
};
A. kind of relationship

B. has a relationship B

C. Inheritance

D. Both A and B
Q10 What does a class hierarchy depict?

A. It shows the relationships between the classes in the form of an organization chart.

B. It describes "has a" relationships.

C. It describes "kind of" relationships.C

D. It shows the same relationship as a family tree.


Q11 What is output of below program?
int main()
{
int i;
for(i=0; i<5; i++);
{
Cout<<"PANKAJ <<endl;
}

return 0;
}

(A) PANKAJ is printed 5 times


(B) Compilation Error B
(C) PANKAJ is printed 1 times
(D) Nothing is printed

Q12 . Can main() function be made private?

a) Yes, always
b) Yes, if program doesn’t contain any classes
c) No, because main function is user defined
d) No, never D

Q13 Private member functions ____________

a) Can’t be called from enclosing class A


b) Can be accessed from enclosing class
c) Can be accessed only if nested class is private
d) Can be accessed only if nested class is public

Q14 Which of the following is not a type of constructor?

a. Copy constructor
b. Friend constructor B
c. Default constructor
d. Parameterized constructor
Q15 What is output of below program?

int main()
{
for(; ;);
for(; ;);
printf("Hello");
return 0;
}
(A) Compilation Error
(B) Runtime Error
(C) Hello is printed one time
(D) Hello is printed infinite times D

Q16 Which of the following concepts means determining at runtime what method to
invoke?
a.Data hiding
b.Dynamic Typing
c. Dynamic binding
d. Dynamic loading
Q17 Which of the following correctly describes overloading of functions?
a. Virtual polymorphism
b. Transient polymorphism
c. Ad-hoc polymorphism
d. Pseudo polymorphism
Q18 A constructor that accepts __________ parameters is called the default constructor.
a. One
b. Two
c. Three
d. No D
Q19 Can a class have virtual destructor?
a. Yes A
b. No
c. May be
d. None of above
Q20 Which constructor function is designed to copy objects of the same class type?

Q21 What is an abstract class in c++


a. Class specifically used as a class with atleast one virtual functions
b. Class specifically used as a base class with atleast one pure virtual functionsB
c. Class from which any class is derived
d. Any class in c++ is an abstract
Q22 Class is pass by _______
a) Value
b) ReferenceB
c) Value or Reference, depending on program
d) Copy
Q23 Which is most appropriate comment on following class definition?

class Student
{
int a;
public : float a;
};
a) Error : same variable name can’t be used twiceA
b) Error : Public must come first
c) Error : data types are different for same variable
d) It is correct

Q24 Size of a class is _____________


a) Sum of the size of all the variables declared inside the class
b) Sum of the size of all the variables along with inherited variables in the class
c) Size of the largest size of variable
d) Classes doesn’t have any sizeD

Q25 Which among the following handles the undefined class exception in program?

A. ClassNotFound
B. NoClassException B
C.ClassFoundException
D. ClassNotFoundException handles the undefined class exception in program

Q26 What is output of below program?


int main()
{
const int a = 10;
printf("%d",++a);
return 0;
}

(A) 11
(B) 10
(C) Compilation Error C
(D) 0Q27 What is meant by multiple inheritance?
A. Deriving a base class from derived class
B. Deriving a derived class from base class
C. Deriving a derived class from more than one base class
D. None of the mentioned

Q28 What is storage class for variable A in below code?

int main()
{
int A;
A = 10;
printf("%d", A);
return 0;
}
(A) extern
(B) auto B
(C) register
(D) static
Q29 Which symbol is used to create multiple inheritance?
A. Dot
B. CommaB
C. Dollar
D. None of the above

Q30What is the output of this program?

class Base
{
public:
Base(){}
~Base(){}
protected:
private:
};
class Derived:public Base
{
public:
Derived(){}
Derived(){}
private:
protected:
};
int main()
{
cout << "Executed" << endl;
}

A. Executed
B. ErrorB
C. Runtime error
D. None of the mentioned
Q31Which of the following is true about the following program
class Base1
{
public:
~Base1() { cout << " Base1" << endl; }
};

class Base2
{
public:
~Base2() { cout << " Base2" << endl; }
};

class Derived: public Base1, public Base2


{
public:
~Derived() { cout << " Derived" << endl;
}
};

int main()
{
Derived d;
return 0;
}
A. Base1 Base2 Derived
B. Derived Base2 Base1B
C. Derived
D. Compiler Dependent
Q32 What will be the output of the following C++ code?

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;
}

a) DerivedOne
b) DerivedTwo
c) Error
d) DerivedThree

Q33 What would be the behaviour if this() and super() used in a method?
a) Runtime error
b) Throws exception
c) compile time error C
d) Runs successfully

Q34 Which of the following is the correct class of the object cout?

A. iostream

B. istream

C. Ostream C

D. ifstream
Q35 Which of the following functions are performed by a constructor?

A NEW
B. Construct a new object

C. Construct a new function

D. Initialize objects D
Q36 More than one user-defined functions can have the same name and perform different
operations. This is a powerful feature of C++ and is known as —-

a. inheritance
b. operator loading
c. function overloading C
d. both c and b
Q.37 (i) ‘ios’ is the base class of ‘istream’
(ii) All the files are classified into only 2 types. (1) Text Files (2) Binary Files.

A - Only (i) is true


B - Only (ii) is true
C - Both (i) & (ii) are true
D - Both (i) & (ii) are false
Q.38 What is the output of the following program?

void main() {
char *s = "C++";

cout<<s<<" ";
s++;
cout<<s<<" ";
}

A - C++ C++
B - C++ ++
C - ++ ++
D - Compile error
Q39 What the output of following C++ program?
class Empty {};

int main()
{
cout << sizeof(Empty);
return 0;
}

A a none zero value A


B 0
C Compiler Error
D Runtime Error
Q40 What is the syntax of inheritance of class?

A. class name

B. class name : access specifer

C. class name : access specifer class name C


D. None of the mentioned

Q41.What is true about constructor?

a) It can contain return type


b) It can take any number of parameters B
c) It can have any non access modifiers
d) Constructor cannot throw an exception

Q.42 What is true about protected constructor?

a) Protected constructor can be called directly


b) Protected constructor can only be called using super() B
c) Protected constructor can be used outside package
d) protected constructor can be instantiated even if child is in a different package
Q43 The number of structures than can be declared in a single statement is

(A) One
(B) Two
(C) Three
(D) Unlimited D

Q44 The order in which operands are evaluated in an expression is


predictable if the operator is

A. Addition
B. Modulus
C. Multiply
D. DIVISION

Q.45 The output of this program is


int a = 10; void main()
{
int a = 20;
cout << a << ::a;
}
a. Syntax error
b. 10 20
c. 20 10
d. 20 20
Q.46 Which of the following functions below can be used Allocate space for array in
memory?
a. calloc()

b. malloc()

c. Realloc()

d. both a and b D

Q.47 The return value of the following code is


Class1& test(Class1 obj)
{
Class1 *ptr = new Class1();
.........
return ptr;
}

b. object of Class1
c. reference to ptr B

d. reference of Class1

e. object pointed by ptr

Q.48 The output of this program is

int

main ()
{
cout << "Hello World!" return 0;
}

a. Hello World

b. Syntax error B

c. 0

d. Hello World!

Q.49 Under which of the following circumstances, synchronization takes


place?

A.When the file is closed


B.When the buffer is empty
C.Explicitly, with manipulators
D.both a and c

Q.50 STL is based on which of the following programming paradigms?

a. Structured Programming A
b. Object Oriented Programming (OOP)
c. Functional Programming
d. Aspect Oriented Programming (AOP)

You might also like