Object Oriented MCQ Number 01271

Object Oriented MCQ Set 1

1. Which among the following best describes member function overriding?
a) Member functions having same name in base and derived classes
b) Member functions having same name in base class only
c) Member functions having same name in derived class only
d) Member functions having same name and different signature inside main function

Answer

Answer: a [Reason:] The member function which is defined in base class and again in the derived class, is overridden by the definition given in the derived class. This is because the preference is given more to the local members. When derived class object calls that function, definition from the derived class is used.

2. Which among the following is true?
a) Inheritance must not be using when overriding is used
b) Overriding can be implemented without using inheritance
c) Inheritance must be done, to use overriding are overridden
d) Inheritance is mandatory only if more than one functions

Answer

Answer: c [Reason:] The inheritance must be used in order to use function overriding. If inheritance is not used, the functions can only be overloaded. There must be a base class and a derived class to override the function of base class.

3. Which is the correct condition for function overriding?
a) The declaration must not be same in base and derived class
b) The declaration must be exactly the same in base and derived class
c) The declaration should have at least 1 same argument in declaration of base and derived class
d) The declaration should have at least 1 different argument in declaration of base and derived class

Answer

Answer: b [Reason:] For a function to be over ridden, the declaration must be exactly the same. There must not be any different syntax used. This will ensure that the function to be overridden is only the one intended from to be overridden from the derived class.

4. Exactly same declaration in base and derived class includes________
a) Only same name
b) Only same return type and name
c) Only same return type and argument list
d) All the same return type, name and parameter list

Answer

Answer: d [Reason:] Declaration includes the whole prototype of the function. The return type name and the parameter list must be same in order to confirm that the function is same in derived and the base class. And hence can be overridden.

5. Which among function will be overridden from the function defined in derived class below:

class A
{
int i;
void show()
{ 
cout<<i; 
}
void print()
{ 
cout <<i; 
}
};
class B
{
int j;
void show()
{ 
cout<<j; 
}
};

a) show()
b) print()
c) show() and print()
d) Compiler time error

Answer

Answer: a [Reason:] The declaration must be exactly same in the derived class and base class. The derived class have defined show() function with exactly same declaration. This then shows that the function in base class is being overridden if show() is called from object of class B.

6. How to access the overridden method of base class from the derived class?
a) Using arrow operator
b) Using dot operator
c) Using scope resolution operator
d) Can’t be accessed once overridden

Answer

Answer: c [Reason:] Scope resolution operator :: can be used to access the base class method even if overridden. To access those, first base class name should be written followed by the scope resolution operator and then the method name.

7. The functions to be overridden _______
a) Must be private in base class
b) Must not be private base class
c) Must be private in both derived and base class
d) Must not be private in both derived and base class

Answer

Answer: b [Reason:] If the function is private in the base class, derived class won’t be able to access it. When the derived class can’t access the function to be overridden then it won’t be able to override it with any definition.

8. Which language doesn’t support method overriding implicitly?
a) C++
b) C#
c) Java
d) SmallTalk

Answer

Answer: b [Reason:] The feature of method overriding is not provided in C#. To override the methods, one must use override or virtual keywords explicitly. This is done to remove accidental changes in program and unintentional overriding.

9. In C# ____
a) Non- virtual or static methods can’t be overridden
b) Non- virtual and static methods only can be overridden
c) Overriding is not allowed
d) Overriding must be implemented using C++ code only

Answer

Answer: a [Reason:] The non-virtual and static methods can’t be overridden in C# language. The restriction is made from the language implicitly. Only the methods that are abstract, virtual or override can be overridden.

10. In Delphi ________
a) Method overriding is done implicitly
b) Method overriding is not supported
c) Method overriding is done with directive override
d) Method overriding is done with the directive virtually

Answer

Answer: c [Reason:] This is possible but only if the method to be overridden is marked as dynamic or virtual. It is inbuilt restriction of programming language. This is done to reduce the accidental or unintentional overriding.

11. What should be used to call the base class method from the derived class if function overriding is used in Java?
a) Keyword super
b) Scope resolution
c) Dot operator
d) Function name in parenthesis

Answer

Answer: a [Reason:] The keyword super must be used to access base class members. Even when overriding is used, super must be used with the dot operator. The overriding is possible.

12. In Kotlin, the function to be overridden must be ________
a) Private
b) Open
c) Closed
d) Abstract

Answer

Answer: b [Reason:] The function to be overridden must be open. This is a condition in Kotlin for any function to be overridden. This avoids accidental overriding.

13. Abstract functions of a base class _____
a) Are overridden by the definition in same class
b) Are overridden by the definition in parent class
c) Are not overridden generally
d) Are overridden by the definition in derived class

Answer

Answer: d [Reason:] The functions declared to be abstract in base class are redefined in derived classes. That is, the functions are overridden by the definitions given in the derived classes. This must be done to give at least one definition to each undefined function.

14. If virtual functions are defined in the base class then ___
a) It is not necessary for derived classes to override those functions
b) It is necessary for derived classes to override those functions
c) Those functions can never be derived
d) Those functions must be overridden by all the derived classes

Answer

Answer: a [Reason:] The derived classes doesn’t have to redefine and override the base class functions. If one definition is already given it is not mandatory for any derived class to override those functions. The base class definition will be used.

15. Which feature of OOP is exhibited by the function overriding?
a) Inheritance
b) Abstraction
c) Polymorphism
d) Encapsulation

Answer

Answer: c [Reason:] The polymorphism feature is exhibited by function overriding. Polymorphism is the feature which basically defines that same named functions can have more than one functionalities.

Object Oriented MCQ Set 2

1. What are automatic variables?
a) Global variables
b) Implicit/temporary variables
c) Local variables
d) System variables

Answer

Answer: c [Reason:] The local variables are also known as automatic variables. The variables in any local scope that are created and destroyed as the program executes its scope.

2. The memory for automatic variables ___
a) Have to be allocated and deallocated explicitly
b) Are allocated and deallocated automatically
c) Is never actually allocated
d) Are never safe

Answer

Answer: b [Reason:] The memory is allocated and deallocated automatically for the automatic variables. As soon as the variable comes in scope, the memory is allocated. The variables are destroyed as soon as those go out of scope.

3. Scope of an automatic variable ___
a) Is actually the whole program
b) Is actually never fixed
c) Is always equal to the whole program execution
d) Is actually function or block in which it is defined

Answer

Answer: d [Reason:] The automatic variables scope is limited only within the block or the function where those are defined. This is property of all the automatic variables.

4. Which among the following is true for automatic variables in general?
a) Automatic variables are invisible to called function
b) Automatic variables are always visible to the called function
c) Automatic variables can’t interact with the called function
d) Automatic variables can’t be variable

Answer

Answer: a [Reason:] The automatic variables are hidden from the called function. Even if passed by reference or address, the address of the variable is used and not the actual variable of calling function. Automatic variables can be const or variable.

5. If an automatic variable is created and then a function is called then ____
a) The automatic variable created gets destroyed
b) The automatic variable doesn’t get destroyed
c) The automatic variable may or may not get destroyed
d) The automatic variable can’t be used in this case

Answer

Answer: b [Reason:] The automatic variables are saved till the called function gets executed. This is done so as to ensure that the program can continue its execution after the called function is returned. The automatic variables gets destroyed only if those go out of scope.

6. Where are the automatic variables stored if another function is called in between the execution of program?
a) Heap
b) Queue
c) Stack
d) Temp variable

Answer

Answer: c [Reason:] All the automatic variables are stored in a new stack entry as soon as their scope is created. If another function is called, the present data is saved in stack and new entry in stack is made for the called function. When the function returns, the automatic variables are used again from where those were left.

7. The static variables of a function ____
a) Are also automatic variables
b) Are not automatic variables
c) Are made automatic by default
d) Can be made automatic explicitly

Answer

Answer: b [Reason:] The static members can’t be automatic. This is because the automatic variables are created and destroyed with each call to a specific function. But the static members remain throughout the execution of program once created.

8. All variables declared within a block ____
a) Are not always automatic
b) Can be made non-automatic
c) Are static by default
d) Are automatic by default

Answer

Answer: d [Reason:] The variables declared inside a block, are make automatic by default. This is to ensure that the variables get destroyed when not required. The variables remain live only till those are required, the life is dependent on the scope of variable.

9. What values does uninitialized automatic variables contain?
a) Null value
b) Void value
c) Undefined/Garbage
d) Zero value

Answer

Answer: c [Reason:] The automatic variable which are not initialized, contain garbage value. If we just declare a variable and try to print its value, the result is some unknown value. The value is garbage as that was not expected value.

10. Constructor of automatic variables is called ____
a) When execution reaches the place of declaration of automatic variables
b) When the program is compiled
c) When the execution is just started
d) Just before the execution of program

Answer

Answer: a [Reason:] Only when the execution reaches the place where the automatic variable was declared, the constructor is called. This is to ensure that the memory is not allocated if not needed. The memory is allocated and then destroyed as soon as it goes out of scope.

11. Does java contain auto or register keywords?
a) Yes, for declaring every type of variable
b) Yes, only to declare cache registers
c) No, because java doesn’t support automatic variables
d) No, java supports local variable concept

Answer

Answer: d [Reason:] The auto and register keywords are not supported in java. Though the same is allowed in java without specifying any of those keywords. The variables are local variables. But java makes it mandatory to initialize all of the local variables in a program.

12. The automatic variables ___
a) Must be declared after its use
b) Must be declared before using
c) Must be declared, can be anytime
d) Must not be initialized

Answer

Answer: b [Reason:] All the automatic variables in a program must be declared before their use. The compiler won’t allow any use of variable if those are not declared before their use.

13. Which error is produced if the automatic variables are used without declaration?
a) Undefined symbol
b) Memory error
c) Type mismatch
d) Statement missing

Answer

Answer: a [Reason:] If the automatic variables are used without declaration or are used before the declaration then the compiler throws an error. The error that the symbol is undefined. The compiler must know everything before that can be used.

14. In perl, using which operator are the local variables created?
a) Dot
b) Arrow
c) Scope resolution
d) my

Answer

Answer: d [Reason:] The language perl supports local variables but the concept is bit different. And if the values are not assigned to the local variables then it contains undef value.

15. How are automatic variables different from the instance variables?
a) Automatic variables are initialized automatically but instances are not
b) Automatic variables are given zero values initially and not instances
c) Instance variables have to be initialized explicitly and automatic implicitly
d) Instance variables are initialized implicitly while automatic are not

Answer

Answer: d [Reason:] The automatic variables have to be initialized explicitly. But in case of instances, those are initialized automatically during execution of program. The conventions are mandatory.

Object Oriented MCQ Set 3

1. Which among the following best defines the hybrid inheritance?
a) Combination of two or more inheritance types
b) Combination of same type of inheritance
c) Inheritance of more than 7 classes
d) Inheritance involving all the types of inheritance

Answer

Answer: a [Reason:] When more than one type of inheritance are used together, it results in new type of inheritance which is in general known as hybrid inheritance. This may of may not have better capabilities.

2. How many types of inheritance should be used for hybrid ?
a) Only 1
b) Ateast 2
c) At most two
d) Always more than 2

Answer

Answer: b [Reason:] There must be combination of at least 2 types of inheritance. The inheritance should be of different type.

3. If single inheritance is used with class A and B. A is base class. Then class C,D and E where C is base class and D is derived from C, then E is derived from D. Class C is made to inherit from class B. Which is the resultant type ?
a) Single level
b) Multilevel
c) Hybrid
d) Multiple

Answer

Answer: b [Reason:] The statement represents multilevel inheritance. It is not hybrid since looking at complete idea, one can’t differentiate whether two type of inheritance are used. Hence it is multilevel inheritance.

4. Diamond problem includes ____ hybrid inheritance
a) Hierarchical and Multiple
b) Hierarchical and Hierarchical
c) Multiple and Multilevel
d) Single, Hierarchical and Multiple

Answer

Answer:a [Reason:] The diamond problem arises when more than one classes are derived from one class and then those classes are used to derive single clas. Resulting in ambiguity of same functions from each class.

5. If ______ inheritance is done continuously, it is similar to tree structure.
a) Hierarchical
b) Multiple
c) Multilevel
d) Hierarchical and Multiple

Answer

Answer: a [Reason:] Hierarchical inheritance is deriving more than one classes from a base class, it it is done continuously and subsequently, it results forming a tree like structure of classes being linked.

6. Which amongst the following is true for hybrid inheritance?
a) Constructor calls are in reverse
b) Constructor calls are priority based
c) Constructor of only derived class is called
d) Constructor calls are usual

Answer

Answer: d [Reason:] The constructors will be called in usual way. First the parent class Constructor and then the derived class Constructors. This is done to initialise all the members properly.

7. Which type of inheritance must be used so that the resultant is hybrid?
a) Multiple
b) Hierarchical
c) Multilevel
d) None

Answer

Answer: d [Reason:] The use of any specific type is not necessary. Though the final structure should not be the same, it should represent more than one type of inheritance if class diagram is drawn.

8. The private member’s are made public to all the classes in inheritance.
a) True
b) False

Answer

Answer: b [Reason:] The private member’s scope can’t be changed and those can never be accessed in other classes. Only the class containing private member’s can access it’s own members.

9. If hierarchical inheritance requires to inherit more than one class to single class, which syntax is correct? ( A,B,C are class names )
a) hierarchical class A: public B, public C
b) multiple class A: public B, public C
c) many class A: public B, public C
d) class A: public B, public C

Answer

Answer: d [Reason:] The syntax is as same as declaration of other classes. There is no specific keyword defined for using hybrid inheritance in programming. Only thing is to specify the classnames seperated by commas.

10. What is the maximum number of classes allowed in hybrid inheritance?
a) 7
b) 127
c) 255
d) As many as required

Answer

Answer: d [Reason:] The classes in any type of inheritance can inherit as many classes as required. The only condition that may arise is memory management. The classes can inherit most of the features from more than one class.

11. What is the minimum number of classes to be there in a program implementing hybrid inheritance?
a) 2
b) 3
c) 4
d) No limit

Answer

Answer: d [Reason:] The answer is no limit. There is no condition defined for limit of classes that has to be used in hybrid. Though you must have at least 4 classes so that one set of multiple or hierarchical inheritance is there and one more class to use single level inheritance.

12. If object of lowest level class is created ( last derived class ), _____ of its parent class constructors are called.
a) Few
b) All
c) Only parent and parent
d) Base and Derived

Answer

Answer: c [Reason:] When derived class object is created, all of its successor parent classes constructors are called. Constructor of all the connected classes is not created. Since the parent members have to be initialised, but other derived classes are not needed.

13. If hybrid inheritance is used, it mostly shows ___ feature of OOP.
a) Flexibility
b) Reusability
c) Efficiency
d) Code readability

Answer

Answer: b [Reason:] The code is reusable in most of the classes and the data becomes more linked to other classes. Other features are also exhibited, but the code reusability is used the most. Code readability becomes relatively less. Felxibility increases but it depends on how the hybrid inheritance is used.

14. The sequence of destructors being called while using hybrid inheritance is ______
a) Reverse of constructors being called
b) Reverse of classes being made
c) Reverse of objects being created
d) Reverse of code calling objects

Answer

Answer: a [Reason:] The destructors are always called in reverse order of constructors being called always. The type of inheritance doesn’t matter. The only important concept is the sequence of classes being inherited.

15. Overloading operators are possible only by using hybrid inheritance.
a) True
b) False

Answer

Answer: b [Reason:] The overloading concept is not related to the types of inheritance being used. Overloading operators can be done without using inheritance. You don’t even have to use more than one class for operator overloading.

Object Oriented MCQ Set 4

1. What is new operator?
a) Allocates memory for an object or array
b) Allocates memory for an object or array and returns a particular pointer
c) Used as return type when an object is created
d) Used to declare any new thing in a program

Answer

Answer: b [Reason:] The new keyword is used to allocate memory of an object or array. The new object or array can be of any type. Then it return a suitable non zero pointer to the object.

2. Microsoft C++ Components extensions support new key word to _______
a) Modify a vtable
b) Replace a vtable slot entry
c) Add new vtable slot entries
d) Rearrange vtable slot entries

Answer

Answer: c [Reason:] The new keyword is used for adding new vtable slot entries. This is an additional feature in Microsoft C++. It can use predefined class object for this work.

3. What happens when new fails?
a) Returns zero always
b) Throws an exception always
c) Either throws an exception or returns zero
d) Terminates the program

Answer

Answer: c [Reason:] While creating new objects, the new operator may fail because of memory errors or due to permissions. At that moment the new operator returns zero or it may throw an exception. The exception can be handled as usual.

4. If new throws an error, which function can be called to write a custom exception handler?
a) _set_handler
b) _new_handler
c) _handler_setter
d) _set_new_handler

Answer

Answer: d [Reason:] If the default exception handler have to be replaced by a user defined handler, we can call _set_new_handler run-time library function with the function name as an argument. This lets the programmer to give a custom definition for handling new operator failure.

5. In C++, if new operator is used, when is the constructor called?
a) Before the allocation of memory
b) After the allocation of memory
c) Constructor is called to allocate memory
d) Depends on code

Answer

Answer: b [Reason:] The constructor function is called after the allocation of memory. In C++ the feature works in a bit different way. The memory for all the data members is allocated first and then the constructor function is called to finalize the memory allocated.

6. Which among the following is correct syntax to declare a 2D array using new operator?
a) char (*pchar)[10] = new char[][10];
b) char (pchar) = new char[][10];
c) char (*char) = new char[10][];
d) char (*char)[][10]= new char;

Answer

Answer: a [Reason:] The new operator usage to declare a 2D array requires a pointer and size of array to be declared. Data type and then the pointer with size of array. The left index can be left blank or any variable can be assigned to it.

7. For declaring data by using new operator ____
a) Type name can’t contain const
b) Type name can’t contain volatile
c) Type name can’t contain class declarations
d) Type name can’t contain const, volatile, class declaration or enumerations

Answer

Answer: d [Reason:] The declaration of any data where we use new operator, any of the mentioned types are not allowed. This is because the new operator allocated memory based on the type of data which can be allocated dynamically.

8. The new operator _______
a) Can allocate reference types too
b) Doesn’t allocate reference types
c) Can allocate reference to objects
d) Doesn’t allocate any data

Answer

Answer: b [Reason:] The new operator doesn’t allocate reference types. This is because the reference types are not objects. The new operator is used to allocate memory to the direct objects.

9. Which among the following is true?
a) New operator can’t allocate functions but pointer to functions can be allocated
b) New operator can allocate functions as well as pointer to functions
c) New operator can allocate any type of functions
d) New operator is not applicable with functions allocation

Answer

Answer: a [Reason:] The new operator can’t allocate functions but can allocate pointer to the functions. This is a security feature as well as to reduce the ambiguity in code. The new keyword is not given functionality to directly allocate any function.

10. Which among the following is added in grammar of new operator?
a) Finalize
b) Arg
c) Initializer
d) Allocator

Answer

Answer: c [Reason:] The new operator grammar is added with an initializer field. This can be used to initialize an object with a user defined constructor. Hence can allocate memory as intended by the programmer.

11. Initializers ______
a) Are used for specifying arrays
b) Are used to defined multidimensional arrays
c) Can’t be specified for arrays
d) Can’t be specified for any data

Answer

Answer: c [Reason:] The initializers can’t be specified for arrays. The initializers can create arrays of object if and only if the class has a default constructor. That is a zero argument constructor so that it can be called without any argument.

12. The objects allocated using new operator ____
a) Are destroyed when they go out of scope
b) Are not destroyed even if they go out of scope
c) Are destroyed anytime
d) Are not destroyed throughout the program execution

Answer

Answer: b [Reason:] It is not necessary that the objects get destroyed when they go out of scope if allocated by using new operator. This is because new operator returns a pointer to object that it had allocated. A suitable pointer with proper scope should be defined by the programmer explicitly.

13. The new operator _____
a) Invokes function operator new
b) Doesn’t invoke function operator new
c) Invokes function operator only if required
d) Can’t invoke function operator new implicitly

Answer

Answer: a [Reason:] The new operator invokes function operator new. This is done to allocate the storage to an object. ::operator new is called for storage allocation impicitly.

14. If new operator is defined for a class and still global new operator have to be used, which operator should be used with the keyword new?
a) Colon
b) Arrow
c) Dot
d) Scope resolution

Answer

Answer: d [Reason:] As usual, scope resolution operator is used to get the scope of parent or the global entities. Hence we can use scope resolution operator with the new operator to call the global new operator even if new operator is defined for the class explicitly.

15. How does compiler convert “::operator new” implicitly?
a) ::operator new( sizeof( type ) )
b) ::operator new( sizeof( ) )
c) new operator :: type sizeof( type )
d) new sizeof( type ) operator

Answer

Answer: a [Reason:] The compiler implicitly converts the syntax so that the instruction can be understood by the processor and proper machine code can be generated. The conversion is done implicitly and no explicit syntax is required.

ed010d383e1f191bdb025d5985cc03fc?s=120&d=mm&r=g

DistPub Team

Distance Publisher (DistPub.com) provide project writing help from year 2007 and provide writing and editing help to hundreds student every year.