250+ TOP MCQs on Abstract Class and Answers

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

1. Which among the following best describes abstract classes?
a) If a class has more than one virtual function, it’s abstract class
b) If a class have only one pure virtual function, it’s abstract class
c) If a class has at least one pure virtual function, it’s abstract class
d) If a class has all the pure virtual functions only, then it’s abstract class
Answer: c
Clarification: The condition for a class to be called abstract class is that it must have at least one pure virtual function. The keyword abstract must be used while defining abstract class in java.

2. Can abstract class have main() function defined inside it?
a) Yes, depending on return type of main()
b) Yes, always
c) No, main must not be defined inside abstract class
d) No, because main() is not abstract function
Answer: b
Clarification: This is a property of abstract class. It can define main() function inside it. There is no restriction on its definition and implementation.

3. If there is an abstract method in a class then, ________________
a) Class must be abstract class
b) Class may or may not be abstract class
c) Class is generic
d) Class must be public
Answer: a
Clarification: It is a rule that if a class have even one abstract method, it must be an abstract class. If this rule was not made, the abstract methods would have got skipped to get defined in some places which are undesirable with the idea of abstract class.

4. If a class is extending/inheriting another abstract class having abstract method, then _______________________
a) Either implementation of method or making class abstract is mandatory
b) Implementation of the method in derived class is mandatory
c) Making the derived class also abstract is mandatory
d) It’s not mandatory to implement the abstract method of parent class
Answer: a
Clarification: Either of the two things must be done, either implementation or declaration of class as abstract. This is done to ensure that the method intended to be defined by other classes gets defined at every possible class.

5. Abstract class A has 4 virtual functions. Abstract class B defines only 2 of those member functions as it extends class A. Class C extends class B and implements the other two member functions of class A. Choose the correct option below.
a) Program won’t run as all the methods are not defined by B
b) Program won’t run as C is not inheriting A directly
c) Program won’t run as multiple inheritance is used
d) Program runs correctly
Answer: d
Clarification: The program runs correctly. This is because even class B is abstract so it’s not mandatory to define all the virtual functions. Class C is not abstract but all the virtual functions have been implemented will that class.

6. Abstract classes can ____________________ instances.
a) Never have
b) Always have
c) Have array of
d) Have pointer of
Answer: a
Clarification: When an abstract class is defined, it won’t be having the implementation of at least one function. This will restrict the class to have any constructor. When the class doesn’t have constructor, there won’t be any instance of that class.

7. We ___________________ to an abstract class.
a) Can create pointers
b) Can create references
c) Can create pointers or references
d) Can’t create any reference, pointer or instance
Answer: c
Clarification: Even though there can’t be any instance of abstract class. We can always create pointer or reference to abstract class. The member functions which have some implementation inside abstract itself can be used with these references.

8. Which among the following is an important use of abstract classes?
a) Header files
b) Class Libraries
c) Class definitions
d) Class inheritance
Answer: b
Clarification: The abstract classes can be used to create a generic, extensible class library that can be used by other programmers. This helps us to get some already implemented codes and functions that might have not been provided by the programming language itself.

9. Use of pointers or reference to an abstract class gives rise to which among the following feature?
a) Static Polymorphism
b) Runtime polymorphism
c) Compile time Polymorphism
d) Polymorphism within methods
Answer: b
Clarification: The runtime polymorphism is supported by reference and pointer to an abstract class. This relies upon base class pointer and reference to select the proper virtual function.

10. The abstract classes in java can _________________
a) Implement constructors
b) Can’t implement constructor
c) Can implement only unimplemented methods
d) Can’t implement any type of constructor
Answer: a
Clarification: The abstract classes in java can define a constructor. Even though instance can’t be created. But in this way, only during constructor chaining, constructor can be called. When instance of concrete implementation class is created, it’s known as constructor chaining.

11. Abstract class can’t be final in java.
a) True
b) False
Answer: a
Clarification: If an abstract class is made final in java, it will stop the abstract class from being extended. And if the class is not getting extended, there won’t be another class to implement the virtual functions. Due to this contradicting fact, it can’t be final in java.

12. Can abstract classes have static methods (Java)?
a) Yes, always
b) Yes, but depends on code
c) No, never
d) No, static members can’t have different values
Answer: a
Clarification: There is no restriction on declaring static methods. The only condition is that the virtual functions must have some definition in the program.

13. It is _________________________ to have an abstract method.
a) Not mandatory for an static class
b) Not mandatory for a derived class
c) Not mandatory for an abstract class
d) Not mandatory for parent class
Answer: c
Clarification: Derived, parent and static classes can’t have abstract method (We can’t say what type of these classes is). And for abstract class it’s not mandatory to have abstract method. But if any abstract method is there inside a class, then class must be abstract type.

14. How many abstract classes can a single program contain?
a) At most 1
b) At least 1
c) At most 127
d) As many as required
Answer: d
Clarification: There is no restriction on the number of abstract classes that can be defined inside a single program. The programs can use as many abstract classes as required. But the functions with no body must be implemented.

15. Is it necessary that all the abstract methods must be defined from an abstract class?
a) Yes, depending on code
b) Yes, always
c) No, never
d) No, if function is not used, no definition is required
Answer: b
Clarification: That is the rule of programming language that each function declared, must have some definition. There can’t be some abstract method that remains undefined. Even if it’s there, it would result in compile time error.

250+ TOP MCQs on Overloading Member Functions and Answers

Object Oriented Programming Questions Freshers on “Overloading Member Functions”.

1. What does memory allocation for objects mean?
a) Actual creation and memory allocation for object members
b) Creation of member functions
c) Creation of data members for a class
d) Actual creation and data declaration for object members
Answer: a
Clarification: The memory allocated for the object members indicates actual creation of the object members. This is known as memory allocation for object.

2. Where is the memory allocated for the objects?
a) HDD
b) Cache
c) RAM
d) ROM
Answer: c
Clarification: The memory for the objects or any other data is allocated in RAM initially. This is while we run a program all the memory allocation takes place in some RAM segments. Arrays in heap and local members in stack etc.

3. When is the memory allocated for an object?
a) At declaration of object
b) At compile time
c) When object constructor is called
d) When object is initialized to another object
Answer: c
Clarification: The object memory allocation takes place when the object constructor is called. Declaration of an object doesn’t mean that memory is allocated for its members. If object is initialized with another object, it may just get a reference to the previously created object.

4. Using new is type safe as _______________________
a) It require to be specified with type of data
b) It doesn’t require to be specified with type of data
c) It requires the name of data
d) It allocated memory for the data
Answer: b
Clarification: The new is type safe because we don’t have to specify the type of data that have to be allocated with memory. We can directly use it with data name. Name of the data doesn’t matter though for type of memory allocation though.

5. Which of the following function can be used for dynamic memory allocation of objects?
a) malloc()
b) calloc()
c) create()
d) both malloc() and calloc()
Answer: d
Clarification: The malloc() function can be used to allocate dynamic memory for objects. Function calloc() can also be use. These functions differ in the way they allocate memory for objects.

6. How much memory will be allocated for an object of class given below?

class Test{
int mark1;
int mark2;
float avg;
char name[10];
};

a) 22 Bytes
b) 24 Bytes
c) 20 Bytes
d) 18 Bytes
Answer: a
Clarification: The size of an object of the class given in question will be of size 22 bytes. This is because the size of an object is always equal to the sum of sizes of the data members of the class, except static members.

7. Which keyword among the following can be used to declare an array of objects in java?
a) new
b) create
c) allocate
d) arr
Answer: a
Clarification: The keyword new can be used to declare an array of objects in java. The syntax must be specified with an object pointer which is assigned with a memory space containing the required number of object space. Even initialization can be done directly.

8. When is the memory allocated for an object gets free?
a) At termination of program
b) When object goes out of scope
c) When main function ends
d) When system restarts
Answer: b
Clarification: Whenever an object goes out of scope, the deletion of allocation memory takes place. Actually the data is not deleted, instead the memory space is flagged to be free for further use. Hence whenever an object goes out of scope the object members become useless and hence memory is set free.

9. Which among the following keyword can be used to free the allocated memory for an object?
a) delete
b) free
c) either delete or free
d) only delete
Answer: c
Clarification: The memory allocated for an object is usually automatically made free. But if explicitly memory has to be made free then we can use either free or delete keywords depending on programming languages.

10. Which function is called whenever an object goes out of scope?
a) Destructor function
b) Constructor function
c) Delete function
d) Free function
Answer: a
Clarification: The destructor function of the class is called whenever an object goes out of scope. This is because the destructor set all the resources, acquired by the object, free. This is an implicit work of compiler.

11. Which operator can be used to check the size of an object?
a) sizeof(objectName)
b) size(objectName)
c) sizeofobject(objectName)
d) sizedobject(objectName)
Answer: a
Clarification: The sizeof operator is used to get the size of an already created object. This operator must constail keyword sizeof(objectName). The output will give the number of bytes acquired by a single object of some class.

12. The memory allocated for an object ____________________
a) Can be only dynamic
b) Can be only static
c) Can be static or dynamic
d) Can’t be done using dynamic functions
Answer: c
Clarification: The memory allocation for an object can be static or dynamic. The static memory allocation is when an object is declared directly without using any function usually. And dynamic allocation is when we use some dynamic allocation function to allocate memory for data member of an object.

13. If an object is declared in a user defined function __________________
a) Its memory is allocated in stack
b) Its memory is allocated in heap
c) Its memory is allocated in HDD
d) Its memory is allocated in cache
Answer: a
Clarification: The memory for any data or object that are used in a user defined function are always allocated in the stack. This is to ensure that the object is destroyed as soon as the function is returned. Also this ensures that the correct memory allocation and destruction is performed.

14. In java ______________ takes care of managing memory for objects dynamically.
a) Free collector
b) Dust collector
c) Memory manager
d) Garbage collector
Answer: d
Clarification: The garbage collector in java takes care of the memory allocations and their deletions dynamically. When an object is no more required then the garbage collector deletes the object and free up all the resources that were held by that object.

15. Which operator can be used to free the memory allocated for an object in C++?
a) Free()
b) delete
c) Unallocate
d) Collect
Answer: b
Clarification: The delete operator in C++ can be used to free the memory and resources held by an object. The function can be called explicitly whenever required. In C++ memory management must be done by the programmer. There is no automatic memory management in C++.

Object Oriented Programming for Freshers,

250+ TOP MCQs on Upcasting and Answers

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

1. What is upcasting?
a) Casting subtype to supertype
b) Casting super type to subtype
c) Casting subtype to super type and vice versa
d) Casting anytype to any other type
Answer: a
Clarification: The upcasting concept includes only the casting of subtypes to the super types. This casting is generally done implicitly. Smaller size types can fit into larger size types implicitly.

2. Which among the following is true for upcasting in inheritance?
a) Downward to the inheritance tree
b) Upward to the inheritance tree
c) Either upward or downward
d) Doesn’t apply on inheritance
Answer: b
Clarification: The upcasting concept in inheritance is always applied upward the inheritance tree. The derived class objects can be type casted to any of its parent class type. Since is a relationship applies in general inheritance.

3. Which among the following is safe?
a) Upcasting
b) Downcasting
c) Both upcasting and downcasting
d) If upcasting is safe then downcasting is not, and vice versa
Answer: a
Clarification: The upcasting is always safe since the derived type or the smaller type is converted into the base type or the larger size. This results in allocating a smaller size data into bigger type data. No data is lost in casting, hence safe.

4. Which among the following is the best situation to use upcasting?
a) For general code dealing with only subtype
b) For general code dealing with only supertype
c) For general code dealing with both the supertype and subtype
d) For writing a rigid code with respect to subtype
Answer: b
Clarification: When a general code has to be written where we use only the supertype object or the data of bigger size, then upcasting would be the best option. Since the whole code will require only the supertype name references.

5. Which property is shown most when upcasting is used?
a) Code reusability
b) Code efficiency
c) Complex code simple syntax
d) Encapsulation
Answer: c
Clarification: The code written using upcasting mostly shows complex code in simpler syntax features. This is because the upcasting concept can be applied as polymorphism and to group the similar type of objects.

6. Upcasting and downcasting objects are the same as casting primitive types.
a) True
b) False
Answer: b
Clarification: It is a bit confusing concept since both casting concepts are different. Primitive casting depends on the type and size of data being typecast. Whereas in objects casting, the classes and inheritance order plays a big role.

7. Which casting among the following is allowed for the code given below?

class A
{
	public :int a;
}
class B:public A
{
	int b;
}
main()
{
	B b=new A();  //casting 1
	A a=new B();  //casting 2
}

a) Casting 1
b) Casting 2
c) casting 1 and casting 2
d) casting 1 nor casting 2
Answer: b
Clarification: The casting 2 is correct. The objects casting must be done from derived class object to a parent class object. That is, the object of the superclass can be made an object of subclass only. Vice versa is not possible.

8. If multiple inheritance is implemented, which upcasting will be correct?
a) Upcast to first base class listed in inheritance
b) Upcast to send base class listed in inheritance
c) Upcast to any base class
d) Upcast is not possible
Answer: c
Clarification: The upcasting of derived class object is possible to any base class. This is because the base class object can represent any of its derived classes using upcasting.

9. If class C inherits class B and class B inherits class A ________________
a) Class C object can be upcasted to object of class B only
b) Class C object can be upcasted to object of class A only
c) Class C object can be upcasted to object of either class A or B
d) Class C object can’t be upcasted
Answer: c
Clarification: Both class A and B are parent classes of class C. Class C object hence can be upcasted to any of those class objects. It is not compulsory to upcast to nearest parent.

10. Upcasting is _____________________ without an explicit type cast.
a) Always allowed for public inheritance
b) Always allowed for protected inheritance
c) Always allowed for private inheritance
d) Not allowed
Answer: a
Clarification: The public inheritance shows the most flexible is-a relationship. Hence explicit type casting is not required. Implicit type casting is done by the compiler.

11. Which concept is needed because of implicit type casting use?
a) Static binding
b) Dynamic binding
c) Compile time binding
d) Source code binding
Answer: b
Clarification: Since the implicit type casting allows casting of a base class pointer to refer to its derived class object or even base class object. We need dynamic type casting so that the references can be resolved during execution of program.

12. When are the pointer types known for upcasting the objects?
a) Compile time
b) Runtime
c) Source code build time
d) Doesn’t apply to pointer types
Answer: a
Clarification: The pointer or reference types are known at compile time for the upcasting of an object. This is because the addresses must be known for casting the derived class to base class object.

13. When are the object type known for upcasting the objects?
a) Compile time
b) Runtime
c) Source code build time
d) Doesn’t apply to objects directly
Answer: b
Clarification: The upcasting with objects directly requires runtime resolving. The objects are fixed and address are allocated at compile time. But the execution of a program requires runtime knowledge of object types, for implicit type cast.

14. If two classes are defined “Parent” and “Child” then which is the correct type upcast syntax in C++?
a) Parent *p=child;
b) Parent *p=*child;
c) Parent *p=&child;
d) Parent *p=Child();
Answer: c
Clarification: The syntax must contain the base class name first. So that the parent class object pointer can be declared. Then the object is assigned with the derived class object with & symbol. & symbol is added to get the address of the derived class object.

15. Which among the following is true?
a) Upcasting is possible only for single level inheritance
b) Upcasting is possible only for multilevel inheritance
c) Upcasting is possible only for multiple inheritance
d) Upcasting is possible for any type of inheritance
Answer: d
Clarification: The type of inheritance doesn’t matter with the upcasting concept. Upcasting applies to all types of inheritance. Any derived class object can be upcasted to any of its base class object.

250+ TOP MCQs on Execution of Constructor or Destructor and Answers

Object Oriented Programming Questions Experienced people on “Execution of Constructor or Destructor”.

1. Which among the following best describes the constructors?
a) A function which is called whenever an object is referenced
b) A function which is called whenever an object is created to initialize the members
c) A function which is called whenever an object is assigned to copy the values
d) A function which is called whenever an object is to be given values for members
Answer: b
Clarification: The constructors are special type of functions which are called whenever an object is created. This is to initialize the data members of the class. The constructor allocates memory space for all the data members.

2. Which among the following best describes destructor?
a) A function which is called just before the objects are destroyed
b) A function which is called after each reference to the object
c) A function which is called after termination of the program
d) A function which is called before calling any member function
Answer: a
Clarification: The Destructors are special functions which are called just before an object is destroyed. This functions is responsible to free all the allocated resources to the object. Objects are destroyed whenever those go out of scope.

3. Which among the following represents correct constructor?
a) ()classname
b) ~classname()
c) –classname()
d) classname()
Answer: d
Clarification: The constructors must contain only the class name. The class name is followed by the blank parenthesis or we can have parameters if some values are to be passed.

4. Which among the following is correct syntax for the destructors?
a) classname()
b) ()classname
c) ~classname()
d) -classname()
Answer: c
Clarification: The destructor must have same name as that of the corresponding class. The class name should be preceded by the tilde symbol (~).

5. Which among the following is true?
a) First the constructor of parent classes are called in sequence of inheritance
b) First the constructor of child classes are called in the sequence of inheritance
c) First constructor called is of the object being created
d) Constructors are called randomly
Answer: a
Clarification: First the constructor of parent class are called. The order in which the parent class constructors are called is same in the sequence of inheritance used.

6. What is the sequence of destructors call?
a) Same order as that of the constructors call
b) Random order
c) According to the priority
d) Revere of the order of constructor call
Answer: d
Clarification: The destructors are called in the reverse order as that of the constructors being called. This is done to ensure that all the resources are released in sequence. That is, the derived class destructors will be called first.

7. The destructors _____________________
a) Can have maximum one argument
b) Can’t have any argument
c) Can have more than one argument
d) Can’t have more than 3 arguments
Answer: b
Clarification: The destructors doesn’t have any arguments. The destructors have to be called implicitly whenever an object goes out of scope. The user can’t pass argument to the implicit call.

8. Destructor calls ________________ (C++)
a) Are only implicit
b) Are only explicit
c) Can be implicit or explicit
d) Are made at end of program only
Answer: c
Clarification: The destructors are usually called implicitly whenever an object goes out of scope. The destructors can also be called explicitly if required. The call must be made, implicitly or explicitly.

9. Number of destructors called are ____________
a) Always equal to number of constructors called
b) Always less than the number of constructors called
c) Always greater than the number of constructors called
d) Always less than or equal to number of constructors
Answer: a
Clarification: Destructor will be called only to free the resources allocated for an object. The resources are allocated only the constructor for an object is called.

10. For explicit call _________________
a) The destructor must be private
b) The destructor must be public
c) The destructor must be protected
d) The destructor must be defined outside the class
Answer: b
Clarification: The destructor must be public for explicit calls. If it is made private or protected then it won’t be accessible outside the class. There is no restriction of definition the destructor outside the class.

11. If a class have 4 constructors then it must have 4 destructors also.
a) True
b) False
Answer: b
Clarification: Even if the class have 4 constructors, only one would be used. And only one destructor is allowed.

12. Which among the following is true for destructors?
a) Destructors can be overloaded
b) Destructors can be define more than one time
c) Destructors can’t be overloaded
d) Destructors are overloaded in derived classes
Answer: c
Clarification: The destructors can never be overloaded. The destructors doesn’t have arguments. And to get overloaded, they must have different signature. This is not possible if arguments are not allowed.

13. The constructor _____________
a) Have a return type
b) May have a return type
c) Of derived classes have return type
d) Doesn’t have a return type
Answer: d
Clarification: The constructors doesn’t have any return type. The constructors are intended to allocate the resources for the object. Memory spaces are to be finalized.

14. The destructors ____________
a) Have a return type
b) May have a return type
c) Of derived classes have return type
d) Doesn’t have a return type
Answer: d
Clarification: The destructors are intended to free the memory space. And all the resources that were allocated for the object. The return value is not supported since only memory has to be made free.

15. The destructor can be called before the constructor if required.
a) True
b) False
Answer: b
Clarification: The destructors can be called only after the constructor calls. It is not a mandatory rule but the deletion can only take place if there is something created using the constructor.

Object Oriented Programming for Experienced people,

250+ TOP MCQs on Template Class and Answers

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

1. A template class can have _____________
a) More than one generic data type
b) Only one generic data type
c) At most two data types
d) Only generic type of integers and not characters
Answer: a
Clarification: The template class can support more than one data type. The only thing is to add all the data types required in a list separated by comma within template specification.

2. Which among the following is the proper syntax for the template class?
a) template ;
b) Template ;
c) template T named(T x, T y){ }
d) Template T1 named(T1 x, T2 y){ }
Answer: c
Clarification: The syntax must start with keyword template, case sensitive. Then it should include the typename and a variable to denote it. Then whenever that variable is used, it replaces it with the data type needed.

3. Can default arguments be used with the template class?
a) Yes, in some special cases
b) Yes, always
c) No, it must satisfy some specific conditions first
d) No, it can’t be done
Answer: b
Clarification: The template class can use default arguments. This is used to specify the data type to be considered if it is not specified while passing to the generic class. The default type will be used.

4. What is the syntax to use explicit class specialization?
a) template class myClass<>{ }
b) template class myClass{ }
c) template <> class myClass<>{ }
d) template <> class myClass{ }
Answer: d
Clarification: The class specialization is creation of explicit specialization of a generic class. We have to use template<> constructor for this to work. It works in the same way as with explicit function specialization.

5. Which is the most significant feature that arises by using template classes?
a) Code readability
b) Ease in coding
c) Code reusability
d) Modularity in code
Answer: c
Clarification: The code reusability is the feature that becomes more powerful with the use of template classes. You can generate a single code that can be used in variety of programming situations.

6. A template class defines the form of a class _____________________ it will operate.
a) With full specification of the data on which
b) With full specification of the functions on which
c) Without full specification of the data on which
d) Without full specification of the functions on which
Answer: c
Clarification: The template classes can accept all types of data types. There is no need to specify the data on which the class has to operate. Hence it gives us flexibility to code without worrying about the type of data that might be used in the code.

7. What are the two specializations of I/O template classes in C++?
a) 16-bit character and wide characters
b) 8-bit character and wide characters
c) 32-bit character and locale characters
d) 64-bit characters and locale characters
Answer: b
Clarification: The I/O specialization is made with wide character and 8-bit characters. Wide characters are used to store the characters that might take more than 1 byte of space in memory or any size that is different from the one that the machine is using.

8. Can typeid() function be used with the object of generic classes?
a) Yes, only if default type is given
b) Yes, always
c) No, generic data can’t be determined
d) No, never possible
Answer: b
Clarification: The typeid() function can be used with the objects of generic classes. An instance of a template class will take the type of data that is being used with it. Hence when typeid() function is used, the data type would have already been defined and hence we can get desired result from typeid() function.

9. The _____________ class is a specialization of a more general template class.
a) String
b) Integer
c) Digit
d) Math
Answer: a
Clarification: The string class is more specialized. Since the string must be able to store any kind of data that is given to the string. Hence it needs maximum specialization.

10. How is function overloading different from template class?
a) Overloading is multiple function doing same operation, Template is multiple function doing different operations
b) Overloading is single function doing different operations, Template is multiple function doing different operations
c) Overloading is multiple function doing similar operation, Template is multiple function doing identical operations
d) Overloading is multiple function doing same operation, Template is same function doing different operations
Answer: c
Clarification: The function overloading is multiple functions with similar or different functionality but generic class functions perform the same task on given different types of data.

11. What if static members are declared inside template classes?
a) All instances will share the static variable
b) All instances will have their own static variable
c) All the instances will ignore the static variable
d) Program gives compile time error
Answer: b
Clarification: The generic class have a special case with static members. Each instance will have its own static member. The static members are not shared usually.

12. What is the output of following program?

template <typename T>
void test(const T&x) 
{
    static int count = 0;
    cout &lt;&lt; "x = " &lt;&lt; x &lt;&lt; " count = " &lt;&lt; count &lt;&lt; endl;
    ++count;
    return;
}
 
void main() 
{
    test<int> (2);
    test<int>(2);
    test<double>(2.2);
}

a)

x = 2 count = 0
x = 2.2 count = 0
x = 2.2 count = 0

b)

x = 2 count = 0
x = 2 count = 0
x = 2.2 count = 0

c)

x = 2 count = 0
x = 2 count = 1
x = 2.2 count = 0

d)

x = 2 count = 0
x = 2 count = 1
x = 2.2 count = 2

View Answer

Answer: c
Clarification: For each new type, the class will have separate instance. Here two instances will be created and hence counter for integer goes to 1. And for float value, the count remains 0 for the output.

 
 

13. If template class is defined, is it necessary to use different types of data for each call?
a) No, not necessary
b) No, but at least two types must be there
c) Yes, to make proper use of template
d) Yes, for code efficiency
Answer: a
Clarification: It is not necessary to use different type with each call to the generic function. Data may be of same type with each call but still the function works. We don’t consider other properties like efficiency with this concept because it is made generic to all data type, hence always works.

14. How many generic types can be given inside a single template class?
a) Only 1
b) Only 3
c) Only 7
d) As many as required
Answer: d
Clarification: There is no restriction on the number of types to be used for making the class generic. There can be any number of generic types with a single class. Hence giving flexibility to code with all the data types.

15. Template classes must have at least one static member.
a) True
b) False
Answer: b
Clarification: There is no mandatory condition to have static members inside template class. Not only template, it is not mandatory to have static members anywhere. We can use them as required in the code.

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&lt;&lt;i; 
	}
	void print()
	{ 
		cout &lt;&lt;i; 
	}
};
class B
{
	int j;
	void show()
	{ 
		cout&lt;&lt;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,