Showing posts with label OOP. Show all posts
Showing posts with label OOP. Show all posts

Tuesday, 11 March 2014

OBJECT ORIENTED PROGRAMMING MCQS

1) Which can be passed as an argument to a function? 
 A. Constant
 B. Expression
 C. Another function
 D. All of the above
 Ans:- A

2) A class which can use all the features of an established class,is 
 A. A static class
 B. A super class
 C. A subclass
 D. Overloaded
Ans:-C

3) Use of virtual functions implies 
 A. Overloading
 B. Overriding
 C. Static binding
 D. Dynamic binding
Ans:-  D

4) If a class C is derived from class B, which is derived from class A, all through public inheritance, then a class C member function can access 
 A. Protected and public data only in C and B
 B. Protected and public data only in C
 C. Private data in A and B
 D. Protected data in A and B
Ans:-D

5) A blueprint for a software object is called a 
 A. Object
 B. Class
 C. Instance
 D. None of these
Ans:-B

6) A friend function to a class, C cannot access 
 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
Ans:-D

OBJECT ORIENTED PROGRAMMING MCQS

1) Additional information sent when an exception is thrown may be placed in 
 A. The throw keyword
 B. The function that caused the error
 C. The catch block
 D. An object of the exception class
 Ans:-C

2) It is possible to declare as a friend 
 A. A member function
 B. A global function
 C. A class
 D. All of the above
 Ans:-D

3) In a class specifier ,data or function designated private are accessible 
 A. To any function in the program
 B. Only if you the password
 C. To member functions of that class
 D. Only to public members of the class
Ans:- C

4) 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. a b c
 B. “abc”
 C. abc
 D. ‘abc’
Ans:- C

5) This pointer 
 A. Implicitly points to an object
 B. Can be explicitly used in a class
 C. Can be used to return an object
 D. All of the above
Ans:-D

6) cfront 
 A. is the front end of a C compiler
 B. is the per-process of a C compiler
 C. is a tool that is translated a C++ code to its equivalent C code
 D. None of above
Ans:-C

7) A pure virtual function is a virtual function that 
 A. Has no body
 B. Returns nothing
 C. Is used in base class
 D. Both (A) and (C)
Ans:- D

8) Access to private data 
 A. Restricted to methods of the same class
 B. Restricted to methods of other classes
 C. Available to methods of the same class and other classes
 D. Not an issue because the program will not compile
Ans:-B

9) What will be the output of the following program?
#include<iostream.h>
void main()
{
float x=5,y=2;
int result;
result=x % y;
cout<<result;

 A. 1
 B. 1.0
 C. Error message
 D. 2.5
Ans:-C

10) A function call mechanism that passes arguments to a function by passing a copy of the values of the arguments is __________ 
 A. Call by name
 B. Call by value
 C. Call by reference
 D. Call by value result
Ans:- B

11) _________ members of a base class are never accessible to a derived class. 
 A. Public
 B. Private
 C. Protected
 D. A,B and C
Ans:- B

12) Real world objects contain 
 A. State and behavior
 B. Date and time
 C. Data and information
 D. None of these
Ans:- A

13) This type of inheritance is a mixture of multiple inheritance and hierarchical inheritance 
 A. Single inheritance
 B. Multiple inheritance
 C. Hierarchical inheritance
 D. Hybrid inheritance
Ans:-D

14) In access control in a protected derivation, visibility modes will change as follows 
 A. Private, public and protected become protected
 B. Only public becomes protected
 C. Public and protected become protected
 D. Only private becomes protected
Ans:- C

15) Within a switch statement 
 A. Continue can be used but Break cannot be used
 B. Continue cannot be used but Break can be used
 C. Both Continue and Break can be used
 D. Neither Continue nor Break can be used
Ans:-B

16) A virtual class is the same as 
 A. An abstract class
 B. A class with a virtual function
 C. A base class
 D. None of the above
Ans:-D

17) A struct is the same as a class except that 
 A. There are no member functions
 B. All members are public
 C. Cannot be used in inheritance hierarchy
 D. It does have a this pointer
Ans:- C

18) Which of the following cannot be legitimately passed to a function 
 A. A constant
 B. A variable
 C. A structure
 D. A header file
Ans:-D

19) If x =5, y =2 then x ^y equals________.
(where ^ is a bitwise XOR operator) 
 A. 00000111
 B. 10000010
 C. 10100000
 D. 11001000
Ans:-A

20) In multiple inheritance 
 A. The base classes must have only default constructors
 B. Cannot have virtual functions
 C. Cannot have virtual classes
 D. None of the above
Ans:-C

Monday, 10 March 2014

OBJECT ORIENTED PROGRAMMING MCQS

1) Which of the following is not the characteristic of constructor?
 A.    They should be declared in the public section.
 B.    They do not have return type.
 C.     They can not be inherited.
 D.     They can be virtual.
 Ans:- D


2) The concept of hierarchical classification is related to
 A.    Abstraction
 B.    Inheritance
 C.     Function overloading
 D.     None
Ans:-  B

3) RunTime polymorphism is achieved by ___________
 A.    Friend function
 B.    Virtual function
 C.     Operator overloading
 D.     Function overloading
Ans:-B

4) When the compiler cannot differentiate between two overloaded constructors, they are called
 A.    Overloaded
 B.    Destructed
 C.     Ambiguous
 D.     Dubious
Ans:-C

5) If we create a file by ‘ifstream’, then the default mode of the file is _________
 A.    ios :: out
 B.    ios :: in
 C.     ios :: app
 D.     ios :: binary
Ans:- B

6) The actual source code for implementing a template function is created when
 A.    The declaration of function appears.
 B.    The function is invoked.
 C.     The definition of the function appears.
 D.     None of the above.
Ans:- B

7) A default catch block catches
 A.    All thrown objects
 B.    No thrown objects
 C.     Any thrown object that has not been caught by an earlier catch block
 D.     All thrown objects that have been caught by an earlier catch block
Ans:-C

8) An exception is caused by
 A.    A hardware problem
 B.    A problem in the operating system
 C.     A syntax error
 D.     A run-time error
Ans:-D

9) You separated a derived class name from its access specifier with
 A.    A colon
 B.    Two colons
 C.     Atleast one space
 D.     A semi colon
Ans:- B

10) When a child class function is called,the compiler looks first for a matching function name in the
 A.    Class of the object using the function name
 B.    Immediate ancestor class
 C.     Base class
 D.     Descendant class
Ans:- A

11) The process of extracting the relevant attributes of an object is known as
 A.    Polymorphism
 B.    Inheritence
 C.     Abstraction
 D.     Data hiding
Ans:-  B

12) You may override the class access specifiers
 A.    Public members
 B.    Public and protected members
 C.     Any specific class members you choose
 D.     No class members
Ans:-  C

13) The following can be declared as friend in a class
 A.    An object
 B.    A class
 C.     A public data member
 D.     A private data member
Ans:-B

14) for (; ;)
 A.    means the test which is done using some expression is always true
 B.    is not valid
 C.     will loop forever
 D.     should be written as for( )
Ans:- C

15) Which of the following will produce a value 10 if x = 9.7?
 A.    floor(x)
 B.    abs(x)
 C.     log(x)
 D.     ceil(x)
Ans:-  D

16) An object is
 A.    One instance of a class
 B.    Another word for a class
 C.     A class with static method
 D.     A method that accesses class
Ans:-  A

17) If a base class destructor is not virtual, then
 A.    It can not have a function body
 B.    It can not be called
 C.     It can not be called when accessed from pointer
 D.     Destructor in derived class can not be called when accessed through a pointer to the base class
Ans:-  D

18) Which of the statements is true in a protected derivation of a derived class from a base class?
 A.    Private members of the base class become protected members of the derived class
 B.    Protected members of the base class become public members of the derived class
 C.     Public members of the base class become protected members of the derived class
 D.     Protected derivation does not affect private and protected members of the derived class
Ans:-  C

19) If the variable count exceeds 100, a single statement that prints “Too many” is
 A.    if (count<100) cout << “Too many”;
 B.    if (count>100) cout >> “Too many”;
 C.     if (count>100) cout << “Too many”;
 D.     None of these.
Ans:-  C

20) If you wanted to sort many large objects or structures, it would be most efficient to
 A.    Place them in an array and sort the array.
 B.    Place pointers to them in an array and sort the array.
 C.     Place them in a linked list and sort the linked list.
 D.     Place references to them in an array and sort the array.
Ans:- C

OBJECT ORIENTED PROGRAMMING MCQS

1) ONE SUB CLASS IS DRIVED BY TWO BASE CLASS CALLED:
 A.    SIMPLE INHERITANCE
 B.    MULTIPLE INHERITANCE
 C.     MULTILEVEL INHERITANCE
 D.     HYBRID INHERITANCE
 Ans:-C


2) Runtime polymorphism is achieved by
 A.    Friend function
 B.    Virtual function
 C.     Operator overloading
 D.     Function overloading
Ans:-B

3) The polymorphism can be characterized by the phrase
 A.    One interface,multiple methods
 B.    Multiple interfaces,one method
 C.     One interface,one method
 D.     None of the above
Ans:- A

4) The operator that cannot be overloaded is
 A.    ++
 B.    : :
 C.     ~
 D.     ( )
Ans:-B

5) If an array is declared as int a[4] = {3, 0, 1, 2}, then values assigned to a[0] & a[4] will be
 A.    3, 2
 B.    0, 2
 C.     3, 0
 D.     0, 4
Ans:-C

6) When a sub class is inherited from only one super class .It is known as
 A.    Single inheritance
 B.    Multiple inheritance
 C.     Hierarchical inheritance
 D.     Multilevel inheritance
Ans:- A

7) The address of a variable temp of type float is
 A.    *temp
 B.    &temp
 C.     float& temp
 D.     float temp&
Ans:-B

8) Data members which are static
 A.    Cannot be assigned a value
 B.    Can only be used in static functions
 C.     Cannot be defined in a Union
 D.     Can be accessed outside the class
Ans:- B

9) Usually a pure virtual function
 A.    Has complete function body
 B.    Will never be called
 C.     Will be called only to delete an object
 D.     Is defined only in derived class
Ans:- D

10) A friend function has access to all private and protected members of the class for which it is a friend
 A.    Only private
 B.    Private and protected
 C.     Only protected
 D.     None of the above
Ans:-  B

11) The members of a class, by default, are
 A.    Public
 B.    Protected
 C.     Private
 D.     Mandatory to specify
Ans:-   C

12) A template class
 A.    Is designed to be stored in different containers
 B.    Works with different data types
 C.     Generates objects which must be identical
 D.     Generates classes with different numbers of member functions
Ans:-  B

13) In C++, dynamic memory allocation is accomplished with the operator ____
 A.    new
 B.    this
 C.     malloc( )
 D.     delete
Ans:- A

14) The process of building new classes from existing one is called ______.
 A.    Polymorphism
 B.    Structure
 C.     Inheritance
 D.     Cascading
Ans:- C

15) Which of the following operator can be overloaded through friend function?
 A.    ->
 B.    =
 C.     ( )
 D.     *
Ans:- D

16) A pointer to the base class can hold address of
 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
Ans:-   C

17) A static data member is given a value
 A.    Within the class definition
 B.    Outside the class definition
 C.     When the program is exeuted
 D.     Never
Ans:-D

18) Which of the following is false for cin?
 A.    It represents standard input
 B.    It is an object of istream class.
 C.     It is a class of which stream is an object
 D.     Using cin the data can be read from user’s terminal
Ans:-C

19) Pure virtual functions
 A.    Have to be redefined in the inherited class
 B.    Cannot have public access specification
 C.     Are mandatory for a virtual class
 D.     None of the above
Ans:- A

20) Exception handling is targeted at
 A.    Run-time error
 B.    Compile time error
 C.     Logical error
 D.     All of the above
Ans:-A