Solved 100+ MCQs Object-oriented Programming

Solved 100+  MCQs Object-oriented Programming:

---------------------------------------------------------------------------------------------
What will be the output of following program?
#include<iostream.h>
void main()
{
float x;
x=(float)9/2;
cout<<x;
}


4.5
4.0
4
5

__________________________________________________________________________________
The term __________ means the ability to take many forms. 

Inheritance
Polymorphism
Member function
Encapsulation
      _____________________________________________________________________________________
Runtime polymorphism is achieved by 

Friend function
Virtual function
Operator overloading
Function overloading
      _____________________________________________________________________________________
Access to private data 

Restricted to methods of the same class
Restricted to methods of other classes
Available to methods of the same class and other classes
Not an issue because the program will not compile
      _____________________________________________________________________________________
Additional information sent when an exception is thrown may be placed in 

The throw keyword
The function that caused the error
The catch block
An object of the exception class
      _____________________________________________________________________________________
A static data member is given a value 

Within the class definition
Outside the class definition
When the program is exeuted
Never
      _____________________________________________________________________________________

In a class specifier ,data or function designated private are accessible 

To any function in the program
Only if you the password
To member functions of that class
Only to public members of the class
      _____________________________________________________________________________________
Which of the statements are true ?
I. Function overloading is done at compile time.
II. Protected members are accessible to the member of derived class.
III. A derived class inherits constructors and destructors.
IV. A friend function can be called like a normal function.
V. Nested class is a derived class.


I, II, III
II, III, V
III, IV, V
I, II, IV
      _____________________________________________________________________________________
At which point of time a variable comes into existence in memory is determined by its 

Scope
Storage class
Data type
All of the above
      _____________________________________________________________________________________
When the compiler cannot differentiate between two overloaded constructors, they are called 

Overloaded
Destructed
Ambiguous
Dubious
      _____________________________________________________________________________________
The actual source code for implementing a template function is created when 

The declaration of function appears.
The function is invoked.
The definition of the function appears.
None of the above.
      _____________________________________________________________________________________
Usually a pure virtual function 

Has complete function body
Will never be called
Will be called only to delete an object
Is defined only in derived class
      _____________________________________________________________________________________
Which of the following is the valid class declaration header for the derived class d with base classes b1 and b2?

class d : public b1, public b2
class d : class b1, class b2
class d : public b1, b2
class d : b1, b2
      _____________________________________________________________________________________
The process of extracting the relevant attributes of an object is known as 

Polymorphism
Inheritence
Abstraction
Data hiding
      _____________________________________________________________________________________
What features make C++ so powerful ?

Easy implementation
Reusing old code
Reusing old code
All of the above
      _____________________________________________________________________________________
Which of the following operator can be overloaded through friend function?

->
=
( )
*
      _____________________________________________________________________________________
The keyword friend does not appear in 

The class allowing access to another class
The class desiring access to another class
The private section of a class
The public section of a class
      _____________________________________________________________________________________
Exception handling is targeted at 

Run-time error
Compile time error
Logical error
All of the above
      _____________________________________________________________________________________
Function templates can accept 

Any type of parameters
Only one parameter
Only parameters of the basic type
Only parameters of the derived type
      _____________________________________________________________________________________
If the variable count exceeds 100, a single statement that prints “Too many” is

if (count<100) cout << “Too many”;
if (count>100) cout >> “Too many”;
if (count>100) cout << “Too many”;
None of these.
      _____________________________________________________________________________________
The mechanism that binds code and data together and keeps them secure from outside world is known as

Abstraction
Inheritance
Encapsulation
Polymorphism
      _____________________________________________________________________________________
The operator << when overloaded in a class

must be a member function
must be a non member function
can be both (A) & (B) above
cannot be overloaded
      _____________________________________________________________________________________
To access the public function fbase() in the base class, a statement in a derived class function fder() uses the statement.fbase();

fbase();
fder();
base::fbase();
der::fder();
      _____________________________________________________________________________________
In which case is it mandatory to provide a destructor in a class? 

Almost in every class
Class for which two or more than two objects will be created
Class for which copy constructor is defined
Class whose objects will be created dynamically
      _____________________________________________________________________________________
_________ members of a base class are never accessible to a derived class. 

Public
Private
Protected
A,B and C
      _____________________________________________________________________________________
What is the error in the following code?
class t
{
virtual void print();
}


No error
Function print() should be declared as static.
Function print() should be defined.
Class t should contain data members.
      _____________________________________________________________________________________
It is possible to declare as a friend 

A member function
A global function
A class
All of the above
      _____________________________________________________________________________________
A struct is the same as a class except that 

There are no member functions
All members are public
Cannot be used in inheritance hierarchy
It does have a this pointer
      _____________________________________________________________________________________
C++ was originally developed by

Clocksin and Melish
Donald E.Knuth
Sir Richard Hadlee
Bjarne Stroustrup
      _____________________________________________________________________________________
What is the output of the following code
char symbol[3]={‘a’,‘b’,‘c’};
for (int index=0; index<3; index++)
cout << symbol [index];


a b c
“abc”
abc
‘abc’
      _____________________________________________________________________________________
If we create a file by ‘ifstream’, then the default mode of the file is _________

ios :: out
ios :: in
ios :: app
ios :: binary
      _____________________________________________________________________________________
The following can be declared as friend in a class 

An object
A class
A public data member
A private data member
      _____________________________________________________________________________________
The polymorphism can be characterized by the phrase 

One interface,multiple methods
Multiple interfaces,one method
One interface,one method
None of the above
      _____________________________________________________________________________________
A virtual class is the same as 

An abstract class
A class with a virtual function
A base class
None of the above
      _____________________________________________________________________________________
Member functions, when defined within the class specification 

Are always inline
Are not inline
Are inline by default, unless they are too big or too complicated
Are not inline by default.
      _____________________________________________________________________________________
Assume that we have constructor functions for both base class and derived class. Now consider the declaration in main( ). Base * P = New Derived; in what sequence will the constructor be called ?

Derived class constructor followed by Base class constructor.
Base class constructor followed by derived class constructor.
Base class constructor will not be called.
Base class constructor will not be called.
      _____________________________________________________________________________________
The operator that cannot be overloaded is

++
: :
~
( )
      _____________________________________________________________________________________
Which of the following declarations are illegal?

void *ptr;
char *str = “hello”;
char str = “hello”;
const *int p1;
      _____________________________________________________________________________________
Identify the operator that is NOT used with pointers

->
&
*
>>
      _____________________________________________________________________________________
Which of the following statements is NOT valid about operator overloading? 

Only existing operators can be overloaded
Overloaded operator must have at least one operand of its class type
The overloaded operators follow the syntax rules of the original operator
None of the above
      _____________________________________________________________________________________
Overloading a postfix increment operator by means of a member function takes 

No argument
One argument
Two arguments
Three arguments
      _____________________________________________________________________________________
Which of the following will produce a value 10 if x = 9.7?

floor(x)
abs(x)
log(x)
ceil(x)
      _____________________________________________________________________________________
Which of the following is not the characteristic of constructor? 

They should be declared in the public section.
They do not have return type.
They can not be inherited.
They can be virtual.
      _____________________________________________________________________________________
You may override the class access specifiers 

Public members
Public and protected members
Any specific class members you choose
No class members
      _____________________________________________________________________________________
You separated a derived class name from its access specifier with 

A colon
Two colons
Atleast one space
A semi colon
      _____________________________________________________________________________________
Consider the following statements:
int x = 22,y=15;
x = (x>y) ? (x+y) : (x-y);
What will be the value of x after executing these statements?


22
37
7
5
      _____________________________________________________________________________________
A friend function to a class, C cannot access 

Private data members and member functions
Public data members and member functions
Protected data members and member functions
The data members of the derived class of C
      _____________________________________________________________________________________
The members of a class by default are 

Public
Protected
Private
Mandatory to specify
      _____________________________________________________________________________________
If x =5, y =2 then x ^y equals________.
(where ^ is a bitwise XOR operator)


00000111
10000010
10100000
11001000
------------------------------------------------------------------------------

1. UNIT – 1 (OOP Concepts and Introduction to C++)

1 In structured programming, the problem is divided into various ______.
(A) modules (B) functions
(C) structures (D) objects

2 In Object-oriented programming, the problem is divided into _____.
(A) classes & objects (B) functions
(C) structures (D) modules

3 A class is ____ datatype.
(A) primitive (B) derived
(C) user-defined (D) All of these

4 A class is a collection of ____ and _____.
(A) data-members & member functions (B) data-members, member functions and
main()
(C) data-members, member functions,
main() and include statements
(D) None of these

5 An object is ……
(A) a variable of class datatype. (B) same as a class.
(C) just like a global variable. (D) collection of data-members and
member functions.

6 Wrapping up of data & functions together in a class is known as _____.
(A) Overloading (B) Data Abstraction
(C) Polymorphism (D) Encapsulation

7 Including only necessary details and ignoring additional details while defining a class is
known as ____.
(A) Overloading (B) Data Abstraction
(C) Polymorphism (D) Encapsulation

8 Preventing direct access of data-members of the class from outside world is known as ____.
(A) Polymorphism (B) Encapsulation
(C) Data Hiding. (D) scope resolution.

9 What are cin and cout?
(A) pointers (B) functions
(C) operator (D) stream objects

1Which header file must be included for cin and cout?
(A) stdio.h (B) conio.h
(C) iostream.h (D) Both iostream.h and conio.h

11Creating a new class using one or more existing classes is known as ____.
(A) Polymorphism (B) Encapsulation
(C) overloading (D) inheritance

12Ability of an operator or function call to take different forms is known as ____.
(A) Polymorphism (B) Encapsulation
(C) overloading (D) inheritance

Answers 1 – B 2 – A 3 – C 4 – A 5 – A 6 – D
7 – B 8 – C 9 – C 10 – C 11 – D 12 - A



UNIT – 2 (Control Flow Constructs, Input /Output and Arrays)


1 Which of the following can replace a simple if-else construct?
(A) Ternary operator (B) while loop
(C) do-while loop (D) for loop

2 Which of the following is an entry-controlled loop?
(A) do-while loop (B) while loop
(C) for loop (D) Both (B) and (C)

3 Which of the following is most suitable for a menu-driven program?
(A) do-while loop (B) while loop
(C) for loop (D) All of these

4 Consider the following loop : for(int i=0; i<5; i++) ;
What will be the value of i after this loop?
(A) It will give compilation error. (B) 5
(C) 6 (D) Some Garbage value

5 A switch construct can be used with which of the following types of variable?
(A) int (B) int, char
(C) int, float, char (D) Any basic datatype

6 Which of the following must be present in switch construct?
(A) Expression in ( ) after switch (B) default
(C) case followed by value (D) All of these

7 What is the effect of writing a break statement inside a loop?
(A) It cancels remaining iterations. (B) It skips a particular iteration.
(C) The program terminates immediately. (D) Loop counter is reset.

8 What is the effect of writing a continue statement inside a loop?
(A) It cancels remaining iterations. (B) It skips execution of statements which
are written below it.
(C) The program terminates immediately. (D) Loop counter is reset.

9 What are cin and cout?
(A) pointers (B) functions
(C) operator (D) stream objects

10 Which header file must be included for cin and cout?
(A) stdio.h (B) conio.h
(C) iostream.h (D) Both iostream.h and conio.h

11 Which of the following is NOT correct 1D array declaration?
(A) int a[ ] = {1 , 2 , 3} ; (B) int a[5] = {1 , 2 , 3} ;
(C) int a[5] = {0} ; (D) int a[3] = {1 , 2 , 3, 4 , 5} ;

12 Which of the following is NOT correct 2D array declaration?
(A) int m[ ] [3] = {1 , 2 , 3, 4} ; (B) int m[3][ ] = {1 , 2 , 3, 4} ;
(C) int m[2][3]; (D) int m[R] [C]; (R & C are constants)

Answers

1 – A 2 – D 3 – A 4 – B 5 – B 6 – A
7 – A 8 – D 9 – C 10 – C 11 – D 12 - B


Comments

Popular posts from this blog

Top 16 Mobile App Development Companies in India | App Developers 2017

CCEE CDAC Exam Questions

Important JavaScript Question Answers