250+ TOP MCQs on Overriding Member Functions and Answers

Object Oriented Programming Interview Questions freshers on “Overriding Member Functions”.

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: a
Clarification: 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: c
Clarification: 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: b
Clarification: 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: d
Clarification: 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) Compile time error
Answer: a
Clarification: 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 the 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: c
Clarification: 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: b
Clarification: 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 the method overriding implicitly?
a) C++
b) C#
c) Java
d) SmallTalk
Answer: b
Clarification: 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: a
Clarification: 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: c
Clarification: 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: a
Clarification: 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: b
Clarification: 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: d
Clarification: 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: a
Clarification: 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: c
Clarification: 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 Programming for Interviews,

250+ TOP MCQs on Downcasting and Answers

Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs) on “Downcasting”.

1. What is downcasting?
a) Casting subtype to supertype
b) Casting supertype to subtype
c) Casting subtype to supertype and vice versa
d) Casting anytype to any other type
Answer: b
Clarification: The downcasting concept includes only the casting of supertypes to the sub types. This casting is generally done explicitly. Larger size types are made to fit into small size types explicitly.

2. Which among the following is a mandatory condition for downcasting?
a) It must not be done explicitly
b) It must be done implicitly
c) It must be done explicitly
d) It can’t be done explicitly
Answer: c
Clarification: The downcasting of any object must be done explicitly. This is because the compilers don’t support the implicit conversion of a supertype to subtype.

3. Downcasting is _______________________
a) Always safe
b) Never safe
c) Safe sometimes
d) Safe, depending on code
Answer: b
Clarification: The downcasting concept is made for exception cases. When there is a need to represent an entity in the form which is not suitable for it. Representing a base type in derived type is not right but can be done for special cases.

4. Downcasting ____________________
a) Can result in unexpected results
b) Can’t result in unexpected result
c) Can result only in out of memory error
d) Can’t result in any error
Answer: a
Clarification: The result of downcasting can be unexpected. This is because downcasting is done on the objects into the objects which doesn’t contain any information of data in lateral object.

5. What should be used for safe downcast?
a) Static cast
b) Dynamic cast
c) Manual cast
d) Implicit cast
Answer: b
Clarification: The dynamic cast can be done using the operator dynamic_cast. This converts one type to another type in a safe way.

6. What does dynamic_cast return after successful type casting?
a) Address of object which is converted
b) Address of object that is used for conversion
c) Address of object that is mentioned in the syntax
d) Doesn’t return any address
Answer: a
Clarification: The address of the object which is converted is returned by the dynamic_cast operator. This is done to safely convert the subtype to supertype. This ensures the proper assignment and conversion from one type to another.

7. If dynamic_cast fails, which value is returned?
a) void
b) null
c) void pointer
d) null pointer
Answer: d
Clarification: The null pointer is returned by the dynamic_cast, if it fails. The conversion sometimes fails because of too complex type conversion. The conversion may also fail due to memory or some related issues.

8. Which is the proper syntax of dynamic_cast?
a) dynamic_cast(object)
b) dynamic_cast new (object)
c) dynamic_cast(object)
d) dynamic_cast(object)
View Answer

Answer: c
Clarification: The dynamic_cast is the name of the operator, which is followed by the new type in which the object have to be converted. Then the object name is given. This object name is then used after the type conversion.

9. Which is the exception handler for the exceptions of downcasting?
a) CastException
b) ClassCastingExeption
c) ClassCasting
d) ClassCastException
Answer: d
Clarification: The exception handler for the exceptions produced during the downcasting exception. This handler can be called during runtime to handle any exception thrown.

10. How to prevent the ClassCastExceptions?
a) By using instanceof
b) By using is-a check
c) By using arrow operator with check function
d) By checking type of conversion
Answer: a
Clarification: The instanceof operator can be used to check the compatibility of the conversion. This has to be done to check whether the casting would be safe or not.

11. Java supports direct downcasting.
a) True
b) False
Answer: b
Clarification: The downcasting is not possible in java directly. This has to be done explicitly. The downcasting is not safe but can be checked for safe casting using instanceof function.

12. Which way the downcasting is possible with respect to inheritance?
a) Upward the inheritance order
b) Downward the inheritance order
c) Either upward or downward the inheritance order
d) Order of inheritance doesn’t matter
Answer: b
Clarification: The downcasting is always downward the inheritance order. Since the base class object have to be casted into derived class type. This is a basic definition of downcasting.

13. What happens when downcasting is done but not explicitly defined in syntax?
a) Compile time error
b) Runtime error
c) Code write time error
d) Conversion error
Answer: a
Clarification: The implicit downcasting is not possible. If tried, the compiler produces an error. Since the compiler doesn’t allow coasting to a type that is not compatible.

14. When is the downcasting used?
a) To separate inherited class from base class
b) To write a more complex code
c) To compare two objects
d) To disable one class in inheritance
Answer: c
Clarification: The downcasting can be used whenever there is a need to compare one object to another. Equals() function can be used to compare whether the objects were of same age. We can use getClass() function too.

15. Why is downcasting possible in any language?
a) Because inheritance follows has-a relationship
b) Because inheritance follows is-a relationship
c) Because inheritance doesn’t follow any relationship
d) Because inheritance is not involved in casting
Answer: b
Clarification: The downcasting is possible because the classes in inheritance follow is-a relationship. Hence the derived class is a base class. Which in turn make the downcasting possible.

250+ TOP MCQs on Destructors and Answers

Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs) on ” Destructors”.

1. Which among the following describes a destructor?
a) A special function that is called to free the resources, acquired by the object
b) A special function that is called to delete the class
c) A special function that is called anytime to delete an object
d) A special function that is called to delete all the objects of a class
Answer: a
Clarification: It is used to free the resources that the object might had used in its lifespan. The destructors are called implicitly whenever an object’s life ends.

2. When a destructor is called?
a) After the end of object life
b) Anytime in between object’s lifespan
c) At end of whole program
d) Just before the end of object life
Answer: d
Clarification: The destructor is called just before the object go out of scope or just before its life ends. This is done to ensure that all the resources reserved for the object are used and at last, are made free for others.

3. Which among the following is correct for abstract class destructors?
a) It doesn’t have destructors
b) It has destructors
c) It may or may not have destructors
d) It contains an implicit destructor
Answer: a
Clarification: It doesn’t have destructors. Since an abstract class don’t have constructors, and hence can’t have instances. Having this case, the abstract classes don’t have destructors too, because that would be of no use here.

4. If in multiple inheritance, class C inherits class B, and Class B inherits class A. In which sequence are their destructors called if an object of class C was declared?
a) ~C() then ~B() then ~A()
b) ~B() then ~C() then ~A()
c) ~A() then ~B() then ~C()
d) ~C() then ~A() then ~B()
Answer: a
Clarification: The destructors are always called in the reverse order of how the constructors were called. Here class A constructor would have been created first if Class C object is declared. Hence class A destructor is called at last.

5. Choose the correct sequence of destructors being called for the following code.

class A{   };
class B{   };
class C: public A, public B{   };

a) ~A(), ~B(), ~C()
b) ~B(), ~C(), ~A()
c) ~A(), ~C(), ~B()
d) ~C(), ~B(), ~A()
Answer: d
Clarification: In multiple inheritance, the constructors are called in the sequence of how they are written in inheritance sequence. And the destructors will be called in the reverse order. This can be cross verified just by printing a message from each destructor defined in classes.

6. When is the destructor of a global object called?
a) Just before end of program
b) Just after end of program
c) With the end of program
d) Anytime when object is not needed
Answer: a
Clarification: This is because the lifespan of global object is from start of the program, till the end of the program. And hence program end is the end of global object too. Just before the end of program, the destructor will be called to free the acquired resources by the objects.

7. How the constructors and destructors can be differentiated?
a) Destructor have a return type but constructor doesn’t
b) Destructors can’t be defined by the programmer, but constructors can be defined
c) Destructors are preceded with a tilde (~) symbol, and constructor doesn’t
d) Destructors are same as constructors in syntax
Answer: c
Clarification: The destructors are preceded with the tilde (~) symbol. The name is same as that of the class. These also doesn’t have any return type.

8. Destructors doesn’t accept parameters.
a) True
b) False
Answer: a
Clarification: The destructors doesn’t accept the arguments. Those are just used to free up the resources.

9. Destructors can be ________
a) Abstract type
b) Virtual
c) Void
d) Any type depending on situation
Answer: b
Clarification: The destructors can be virtual. It is actually advised to keep the destructors virtual always. This is done to suppress the problems that may arise if inheritance is involved.

10. Global destructors execute in ___________ order after main function is terminated.
a) Sequential
b) Random
c) Reverse
d) Depending on priority
Answer: c
Clarification: The destructors are always called in reverse order no matter which destructor it is. This is done to ensure that all the resources are able to get free. And no resource is kept busy.

11. When is it advised to have user defined destructor?
a) When class contains some pointer to memory allocated in class
b) When a class contains static variables
c) When a class contains static functions
d) When a class is inheriting another class only
Answer: a
Clarification: This is always advised to have user defined destructor when pointers are involved in class. This is usually done to ensure that the memory, that was allocated dynamically, gets free after use and doesn’t cause memory leak.

12. Which among the following is correct for the destructors concept?
a) Destructors can be overloaded
b) Destructors can have only one parameter at maximum
c) Destructors are always called after object goes out of scope
d) There can be only one destructor in a class
Answer: d
Clarification: This is so because the destructors can’t be overloaded. And the destructor must have the same name as that of class with a tilde symbol preceding the name of the destructor. Hence there can be only one destructor in a class. Since more than one function with same name and signature can’t be present in same scope.

13. Which class destructor will be called first, when following code go out of scope?

class A{  };
class B{  };
class C: public B{  };
A a;
B b;
C c;

a) ~A()
b) ~B()
c) ~C()
d) ~B() and ~C()
Answer: c
Clarification: The constructor that would have created at last, its destructor will be called first when the code goes out of scope. This will help the program to manage the resources more efficiently.

14. When an object is passed to a function, its copy is made in the function and then ______________
a) The destructor of the copy is called when function is returned
b) The destructor is never called in this case
c) The destructor is called but it is always implicit
d) The destructor must be user defined
Answer: a
Clarification: When an object is passed to a function, its copy is made in the function. This copy acts as a real object till the function is live. When the function is returned, the copy’s destructor is called to free the resources held by it.

15. What happens when an object is passed by reference?
a) Destructor is not called
b) Destructor is called at end of function
c) Destructor is called when function is out of scope
d) Destructor is called when called explicitly
Answer: a
Clarification: The destructor is never called in this situation. The concept is that when an object is passed by reference to the function, the constructor is not called, but only the main object will be used. Hence no destructor will be called at end of function.

250+ TOP MCQs on Base Class and Answers

Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs) on “Base Class”.

1. Which is most appropriate definition of a base class?
a) It is parent of any of its derived class
b) It is child of one of the parent class
c) It is most basic class of whole program
d) It is class with maximum number of members
Answer: a
Clarification: A class which is parent of another class, or from which other classes can be derived, is known as a base class. It is mandatory that a class must have at least one derived class to be called as a base class.

2. A base class is also known as _____________ class.
a) Basic
b) Inherited
c) Super
d) Sub
Answer: c
Clarification: A class which is being derived by other classes, is called as super class. This concept is clearly used in java as we call the functions of a base class by using the keyword super as required.

3. An abstract class is always a __________ class.
a) Base
b) Derived
c) Template
d) Nested
Answer: a
Clarification: Every abstract class is a base class. It must be so, because the functions which are not defined inside the abstract class, must be defined in the derived classes. Hence it becomes a base class.

4. How many base classes can a single class inherit in java?
a) 1
b) 2
c) 3
d) As many as required
Answer: a
Clarification: In java, multiple inheritance is not supported, which leads to the fact that a class can have only 1 parent class if inheritance is used. Only if interfaces are used then the class can implement more than one base class.

5. How to make a derived class a base class?
a) Change name of the class
b) Use keyword base
c) Make a class derive from it
d) Can’t be done
Answer: c
Clarification: Making another class derive from it will make that class as base class. It is not necessary that we have to write different code for it. If at least one class derives that class, it becomes the base class for the new class.

6. If a base class is being derived by two other classes, which inheritance will that be called?
a) Single
b) Multiple
c) Multi-level
d) Hierarchical
Answer: d
Clarification: When more than one classes are being derived from a single parent class, the inheritance is known as hierarchical inheritance. This is usually useful when the base class is higher abstraction of its derived classes.

7. Which among the following must be in a base class?
a) Data members
b) Member functions
c) Access specifiers
d) Nothing
Answer: d
Clarification: Even a class that doesn’t have any members can be a base class. It is not mandatory to have any member or attribute in base class.

8. Which type of members can’t be accessed in derived classes of a base class?
a) Protected
b) Private
c) Public
d) All can be accessed
Answer: b
Clarification: The private members can be accessed only inside the base class. If the class is derived by other classes. Those members will not be accessible. This concept of OOP is made to make the members more secure.

9. If a class is enclosing more than one class, than it can be called as base class of those classes.
a) True
b) False
Answer: b
Clarification: When a class have more than one nested classes, it is known as enclosing class. It can’t be called as parent or base class since there is no inheritance involved.

10. Base class have ________________ of abstraction.
a) Higher degree
b) Lower degree
c) Intermediate
d) Minimum degree
Answer: b
Clarification: A base class will have lesser information as compared to those of derived classes. Since derived classes inherit the base class properties and then add on their own features, they elaborate more hence have lower degree of abstraction.

11. Always the base class constructors are called ___________ constructor of derived class.
a) Before
b) After
c) Along
d) According to priority of
Answer: a
Clarification: When the base class object is created, its constructor will be called for sure. But if a derived class constructor is called, first base class constructor is called and then derived class constructor is taken into consideration.

12. Can we call methods of base class using the constructor of the derived class?
a) Yes, always
b) Yes, but not always
c) No, never
d) No, but we can call in some cases
Answer: a
Clarification: If the function is defined in the base class, it can always be called from the constructor of its derived class. Since the constructors are not private, they can be accessed in derived class even if those are protected.

13. If a base class is inherited from another class and then one class derives it, which inheritance is shown?
a) Multiple
b) Single
c) Hierarchical
d) Multi-level
Answer: d
Clarification: If a base class is inherited from another class, single inheritance is shown. But when one more class inherits the derived class, this becomes a multi-level inheritance.

14. How many base classes can a single derived class have in C++?
a) 1
b) 2
c) 3
d) As many as required
Answer: d
Clarification: This is because C++ allows multiple inheritance. A derived class can have more than one base class and hence can derive all of their features.

15. If a base class is added with a few new members, its subclass must also be modified.
a) True
b) False
Answer: b
Clarification: The base class can be added with new members without affecting the subclasses. This is because the subclasses may get some more features inherited but it won’t use them. But the base class will be able to use the new members as would be required.

250+ TOP MCQs on Constant Member Functions and Answers

Object Oriented Programming Quiz on “Constant Member Functions”.

1. What are the constant member functions?
a) Functions which doesn’t change value of calling object
b) Functions which doesn’t change value of any object inside definition
c) Functions which doesn’t allow modification of any object of class
d) Functions which doesn’t allow modification of argument objects
Answer: a
Clarification: The constant member functions are a special type of member functions. These are intended to restrict any modification in to the values of object which is used to invoke that function. This is done to ensure that there are no accidental modifications to the object.

2. Which keyword must be used to declare a member function as a constant member function?
a) Constant
b) Const
c) FunctionConst
d) Unchanged
Answer: b
Clarification: The keyword const is provided in most of the programming languages. This indicates that the member on which it is specified remains constant with the respective values of members. The keyword must be mentioned so as to declare a member function to be constant.

3. Which objects can call the const functions?
a) Only const objects
b) Only non-const objects
c) Both const and non-const objects
d) Neither const not non-const objects
Answer: c
Clarification: All the objects of a class can call const functions for its use. Const objects can call the const functions to since those values are already constant. And the non- const objects can call the const functions to keep their values constant.

4. Non-const functions _______________________
a) Can be called only from non-const object
b) Can be called only from const object
c) Can be called both by const and non-const object
d) Can’t be called with object
Answer: a
Clarification: The non-const functions are able to modify the values of object which called the function. So only the non-const functions can be called. If const object is used then the compiler produces an error as the const object is being given to a function which can modify its values.

5. Which is the correct condition on const member functions?
a) Const member functions can’t call non-const member functions
b) Const member functions can’t call any other function
c) Const member functions can call only the functions which are neither const nor non-const
d) Const member functions can call only data members of call not member functions
Answer: a
Clarification: The const member functions are restricted to call any other non-const member functions. This is to ensure that the const function doesn’t have any code that might modify the calling object.

6. If a const object calls a non-const member function then ____________________
a) Run time error may get produced
b) Compile time error may get produced
c) Either compile time or run time error is produced
d) The program can’t be compiled
Answer: b
Clarification: The program gets compiled but produces an error. The error is produced because a constant value is being changed. Even if there is no code that can change any object value, but non-const member functions are assumed to change the values.

7. Can a constructor function be constant?
a) Yes, always
b) Yes, only if permissions are given
c) No, because objects are not involved
d) No, never
Answer: d
Clarification: The constructors can’t be made const. This is to ensure that the constructor is capable of initializing the values to the members of the object. If it is made constant then it won’t be able to initialize any data member values.

8. A function can have both the const and non-const version in the same program.
a) True
b) False
Answer: a
Clarification: The functions in a program can be made both const and non-const. This feature is made available to make programming more flexible. This ensures the security too as we can call const function whenever required.

9. How is it possible to have both const and non-const version of a function?
a) Function overriding
b) Function prototyping
c) Function overloading
d) Function declaring
Answer: c
Clarification: The functions can be declared const and non-const in the same program. The technique used is function overloading. We can define a const function and then a non-const version of same function using overloading.

10. When both the const and non-const version of functions are required?
a) Return value have to be different in const
b) Return value have to be same in const
c) Return values have to be ignored
d) Return values have to be suppressed
Answer: a
Clarification: The return values can help to overload the functions. Also, this will allow us to use a non-const function to be called inside both the const and non-const version of functions.

11. If a function is to be made const, which is the correct syntax?
a) const functionName(parameters);
b) const returnType functionName(parameters);
c) const functionName(returnType)(Parameters);
d) const (functionName(parameters));
Answer: b
Clarification: The function declaration must contain the keyword const. The const keyword makes the function const type. The usual function declaration can be given followed by the keyword. The keyword const can be given after the declaration of function and before definition.

12. Functions which differ in const-ness are considered ______________________
a) To have same signature
b) To have different signature
c) To produce compile time error
d) To produce runtime error
Answer: b
Clarification: The functions are considered to have different signature. This is because the const-ness also defines the type of function or the working of functions. And hence the functions can be considered different. This is the reason that we can use function overloading for const and non-const version of same function.

13. If const version of a function when overloading is used, the function ___________________
a) Returns reference to object
b) Returns volatile reference
c) Returns mutable reference
d) Returns const reference
Answer: d
Clarification: The function returns a const reference. This is to ensure that the value of object calling the function is not modified. This is a security feature.

14. Which among the following is recommended for const functions?
a) Const function use should be reduced in a program
b) Const function use should be more in a program
c) Const function use should not matter in a program
d) Const function use should be able to modify the values
Answer: b
Clarification: The const member functions should be used more in a program. The reason behind is to ensure there is no accidental modification of data of object. Also to ensure any unintended modification which may result in unexpected termination of program.

15. Use of const member function in a program _________________________
a) Is mandatory, always
b) Is optional, always
c) Is mandatory, if objects are used
d) Is optional, if const objects are used
Answer: b
Clarification: The use of const member functions is not mandatory. If const objects are involved then there is a high use of const member functions too. But there is no mandatory condition.

Object Oriented Programming for Quizzes,

250+ TOP MCQs on New Operator and Answers

Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs) on “New Operator”.

1. What is the 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: b
Clarification: 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 returns a suitable non zero pointer to the object.

2. Microsoft C++ Components extensions support new keyword to _____________
a) Modify a vtable
b) Replace a vtable slot entry
c) Add new vtable slot entries
d) Rearrange vtable slot entries
Answer: c
Clarification: 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: c
Clarification: 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: d
Clarification: If the default exception handler has 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: b
Clarification: 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: a
Clarification: 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: d
Clarification: 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: b
Clarification: 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: a
Clarification: 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: c
Clarification: 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: c
Clarification: 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: b
Clarification: 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: a
Clarification: The new operator invokes function operator new. This is done to allocate the storage to an object. ::operator new is called for storage allocation implicitly.

14. If a 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: d
Clarification: 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: a
Clarification: 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.