Polymorphism & Inheritance MCQ

1.  A normal C++ operator that acts in a special way on newly defined data types is called _______
a) Encapsulated
b) Overloaded [ANS]
c) Classified
d) Inherited

2. Which of the following operator is not overloaded in C++?
a) ++
b) =
c) pow [ANS]
d) <<

3. The correct function name for overloading the addition + operator is __
a) Operator _+
b) Operator :+
c) Operator (+)
d) Operator + [ANS]
4. Which of the following operators cannot be overloaded?
a) → operator
b) . operator [ANS]
c) [ ] operator
d) & operator
5. Which of the following operators cannot be overloaded?
a) +
b) –
c) [ ]
d) :: [ANS]
6. How to declare a function?
a) Operator operator sign [ANS]
b) Operator
c) Operator sign
d) None of these
7. We cannot use friend function to overload _____
a) = operator
b) function call() operator
c) [] subscript operator
d) All of these [ANS]

8. Pick the incorrect statement from the following
a) The overloaded operators follow the syntax rules of original operator.
b) Only existing operators can be overloaded
c) Overloaded operator must have at least one operand of its class type
d) Overloaded operators can change the meaning of the original operator [ANS]

9. For operators to be overloaded as non static member functions:
a) Both binary and unary operators take one argument.
b) Binary operators can have one argument and unary operators can not have any [ANS]
c) Neither binary nor unary operators can have arguments
d) Binary operators can have two arguments and unary operators can have one

10. Which of the following is an operator function?
a) Member overloading
b) Function overloading
c) Operator overloading [ANS]
d) None of these

11. Operator overloading means _______
a) Giving new meaning to existing operator without changing its original meaning
b) Making C++ operators to work with objects
c) Making new types of operator
d) Both a and b [ANS]

12. For overloading =+ implicitly _______
a) + and = operators need to be overloaded implicitly
b) Only + operator need to be overloaded implicitly
c) Only = operator need to be overloaded implicitly
d) The += operator cannot be overloaded implicitly [ANS]

13. Overloading a postfix increment operator by means of a member function takes _____
a) No argument [ANS]
b) One argument
c) Two arguments
d) Three Arguments

14.  If you overload only prefix operator ++ then the postfix ++ operator is ______
a) Does not work
b) Works arbitrarily
c) Works naturally
d) Works as if prefix ++ operator [ANS]

15.  When compiler decides binding of an overloaded member then it is called ______
a) Static binding [ANS]
b) Dynamic binding
c) Local binding
d) None of these

16. One can redefine the working of _______ to work with objects.
a) Preprocessor directives
b) White space characters
c) Standard operators [ANS]
d) None of these

17. Choose the correct option:
I. When you overload << operator the >> operator automatically gets
overloaded
II. You can overload unary operator to work with binary operator
a) Only I is true
b) Only II is true
c) Both I and II are true
d) Neither I nor II are true [ANS]

18. Choose the correct option
I. If you do not want to make use of operator overloading, you can achieve that
effect using user defined function.
II. The sizeof operator can be overloaded
a) Only I is true [ANS]
b) Only II is true
c) Both I and II are true
d) Neither I nor II are true

19. The array subscript operator [] when overloaded cannot ______
a) Take user defined objects are operands
b) Take float as an operand
c) Take multiple values inside (for example: [5,7] ) [ANS]
d) None of these

20. The prototype of overloaded cast operator functions do not _______
a) specify the type they convert to
b) specify the return type [ANS]
c) need to be defined inside the class whose objects are being converted
d) none of these

21. What will be the output of the following program ?
#include
using namespace std;
class TEST
{
public:
int x,y;
TEST( ){};
TEST(int, int);
TEST operator + (TEST);
};
TEST::TEST(int a, int b)
{
x = a;
y = b;
}
TEST TEST::operator+ (TEST ob)
{
TEST temp;
temp.x = x + ob.x;
temp.y = y + ob.y;
return (temp);
}
int main ()
{
TEST a(10,20);
TEST b(1,2);
TEST c;
c = a + b;
cout<< c.x<< “,”<<c.y;
return 0;
}
a) 10 20
b) 1 2
c) 11 22 [ANS]
d) 30 3
22.  Which of the following operators cannot be overloaded ?
a) +=
b) <<
c) ?: [ANS]
d) function call()

23.  Which of the following operators cannot be overloaded ?
a) ::
b) sizeof
c) Conditional operator ?:
d) All of these [ANS]

24. The overloading the function operator________.
a) requires class with overloaded operators [ANS]
b) makes use of parameterized constructor
c) allows to create objects that are syntactically like functions
d) none of these

25. Choose the incorrect statement from the following.
a) Constructors can be overloaded.
b) Only existing operators must be overloaded  [ANS]
c) the overloaded operators must follow the syntax rules of the original operator
d) The overloaded operators must have at least one operand of its class type.

26. Overloading without explicit arguments to an operator function is called______.
a) unary operator [ANS]
b) binary operator
c) nested class
d) none of these

27. In binary overloaded function which are overloaded through friend function take_____. a) three explicit arguments
b) two explicit arguments [ANS]
c) one explicit argument
d) no argument

28. In binary overloaded function which are overloaded through member function take____
a) three explicit arguments
b) two explicit arguments
c) one explicit argument [ANS]
d) no argument

29. The unary operators are overloaded by member function then it takes ________.
a) three explicit arguments
b) two explicit arguments
c) one explicit argument
d) no argument [ANS]

30. Choose the correct choice.
I. All the operators in C++ can be overloaded.
II. We can change the basic meaning of operator while overloading it.
a) Only I is true
b) Only II is true
c) Both I and II are true
d) Neither I nor II are true [ANS]

31. Which of the following operator can be overloaded through friend function ?
a) ::
b) + [ANS]
c) =
d) ->

32.  The name of the operator function that overloads the / symbol is________.
a) operator /() [ANS]
b) /op()
c) / operator()
d) op/()

33. In binary operator overloaded operator function the second operand should be______.
a) passed by value
b) implicit
c) passed by reference [ANS]
d) none of these

34. Following overloaded operator cannot be inherited by derived class_______.
a) >
b) = [ANS]
c) *
d) /
e) +

35.  Choose the correct choice.
a) The conditional operator can be overloaded
b) While overloading using the friend function the binary operator requires one argument
c) Operator precedence cannot be changed [ANS]
d) None of these

36.  Which of the following operator can be overloaded through friend function ?
a) ()
b) []
c) ->
d) * [ANS]

37.  When we overload we want to______.
a) compare and copy object
b) assign one object to another [ANS]
c) compare two objects
d) test for equality

38. Operator overloading is also called one form of polymorphism because_______.
a) the overloaded operators have many forms
b) the overloaded operators can be declared virtual
c) the overloaded function can perform various tasks depending upon the type of object [ANS]
d) none of these

39.  Overloading means
a) two or more methods in the same class that have same name
b) calling the method which has actual parameters
c) two or more methods having same name but present in different class [ANS]
d) none of these

40. In my program I have overloaded TEST::operator+ and TEST::operator= What is the effect on TEST::operator+= ?
a) The TEST::operator+= will be automatically overloaded. First TEST::operator+ will get overloaded and then TEST::operator=
b) The TEST::operator+= will be automatically overloaded. First TEST::operator= will get overloaded and then TEST::operator+
c) TEST::operator+= will become invalid
d) There will be no effect because all three are independent [ANS]

41. The inheritance mechanism provides meaning of deriving______
a) new operator from exciting one
b) new function from exciting one
c) new class from exciting one [ANS]
d) all of these

42. A class derived from the exciting class is known as______
a) new class
b) inheritance
c) derived class [ANS]
d) none of these

43. The derived class is derived from__________
a) derived class
b) base class [ANS]
c) both a&b
d) none of these

44. Which of the following can derived class inherit ?
a) data members
b) member function
c) both a&b [ANS]
d) none of these

45. The inheritance is described as a _____ relationship
a) has a
b) is a [ANS]
c) association
d) none of these

46.  Irrespective of the type of derivation ____members of base class are never accessible in derived class
a) public
b) private [ANS]
c) protected
d) none of these

47.  Which of the following allows you to create derived class that inherits properties from more than one base class ?
a) multilevel inheritance
b) multiple inheritance [ANS]
c) single inheritance
d) Hybrid inheritance

48. The principle by which the knowledge of general category can be applied to more specific objects is called _____
a) polymorphism [ANS]
b) overriding
c) inheritance
d) none of these

49. Parent:child is________
a) base:derived[ANS]
b) derived:driven
c) child:super
d) subclass:superclass

50. What is the syntax of inheritance of a class ?
a) Class class _name
b) Class name:access specifier
c) Class name:access specifier class name [ANS]
d) none of these

51. If an attribute is private then which methods have access to it?
a) Only static methods in the same class
b) Only the methods defined in that class [ANS]
c) Only the methods of the same package
d) none of these

52. What will happen on execution of the following code ?
Class base
{
};
class derived:protected base
{
};
a) It will not compile as the class body of the base class is not defined
b) It will not compile as the class body of the derived class is not
defined
c) It will compile successfully [ANS]
d) The compilation of above code is dependent upon the type of data
provided to it

53. Which of the following advantage cannot be achieved by using multiple inheritance ?
a) polymorphism
b) dynamic binding
c) both a&b [ANS]
d) none of these

54.  Which of the symbol used to create multiple inheritance ?
a) Dot
b) Comma [ANS]
c) Hash #
d) Dollar

55.  Using multiple inheritance
a) there can be virtual class [ANS]
b) it can not be include virtual class
c) the base classes must have only default constructor
d) none of these

56.  The______member function is declared in base class but redefined in derived class
a) class
b) overloaded
c) operator
d) virtual [ANS]

57. In public inheritance
a) code re-usability
b) virtual function overloading
c) sub-typing
d) all the above [ANS]

58. In public inheritance _____
a) All the members of base class are inherited and are made public
b) Members of base class that are not private are inherited and retain their access type
c) All the members of base class are inherited and retain their access type [ANS]
d) Only public members of base class are inherited and they remain public

59.  If class C is derived class of class B and class B is a derived class of A. If we instantiate class B object then the first constructor called belongs to class
a) A [ANS]
b) B
c) can be A or B
d) one cannot achieve such inheritance

60.  When the object of derived class expire, first the ___ is invoked followed by the ___.
a) derived class constructor, base class destructor
b) derived class destructor , base class destructor
c) base class destructor , derived class destructor
d) none of these

61.  If class A inherits from class B then B is called ________ ans A is called _____ of B.
a) superclass and subclass [ANS]
b) subclass and superclass
c) subclass and child class
d) superclass and parent class

62.  What does derived class does not inherit from the base class _______.
a) constructor and destructor
b) operator=() members
c) friends
d) all of these [ANS]

63. Which constructor will initialize the base class data member ?
a) Base class [ANS]
b) Derived class
c) Derived derived class
d) None of these

64. If class A is a friend class of class B, if class B is friend class of class C then ________.
a) class C is friend class of A
b) class A is friend class of class C
c) class A and class C do not have any friendship relation. [ANS]
d) none of these

65.  _________ class is tightly coupled with other class.
a) friend [ANS]
b) virtual
c) abstract
d) none of these

66. The keyword friend is used in ___________.
a) the class allowing access to another class
b) the private section of a class
c) the public section of a class
d) all of these [ANS]

67. What will be the output of the following code?
#include
using namespace std;
class A
{
public:
A(int a)
{
cout<<” ”<<a;
}
};
class B: public A
{
public:
B(int a,int b):A(a)
{
cout<<” ”<<b;
}

};
class C: public B
{
public:
C(int a,int b,int c):B(a,b)
{
cout<<” ”<<c;
}
};
int main()
{
C c(10,20,30);
return 0;
}
a)garbage garbage 30
b)30 20 10
c)10 20 30 [ANS]
d)syntax error

68. What is output of the following code ?
#include
using namespace std;
class Base
{
protected:
int a;
public:
Base(int x)
{
a=x;
}
~Base()
{
}
};
class Derived: public Base
{
int b;
public:
Derived(int x,int y): Base(y)
{
b=x;
}
~Derived()
{ }
void display()
{
cout<<a<<” ”<<b<<endl;

}
}
int main()
{
Derived obj(100,200);
obj.display();
return 0;
}
a) 100 200
b) 200 100 [ANS]
c) Syntax error
d) 100 100

69. What is the output of the following code ?
#include
using namespace std;
class Base
{
public:
Base()
{
cout<<”In Base Class ”<<endl;
}
};
class Derived:public Base
{
public:
Derived()
{
cout<<”In Derived Class”<<endl;
}
};
int main()
{
cout<<”\t Creating Base class object…..”<<endl;
Base b;
cout<<”\t Creating Derived class object…… ”<<endl;
Derived d;
return 0;
}
a) Creating Base class object…..Creating Derived class object……In Base Class….In Derived Class
b) Creating Base class object…..In Base Class Creating Derived class object……In Derived Class
c) Creating Derived class object…..In Base Class Creating Base class object…..In Base Class In Derived Class
d) Creating Base class object…… In Base Class Creating Derived class object……. In Base Class In Derived Class [ANS]

70. What is output of the following code?
#include
using namespace std;
class Base
{
public:
Base(void)
{
cout<<”Base(void)\n”;
}
Base(int_i)
{
cout<<”Base9”<<i<<”)\n”;
};
Base()
{
cout<<”Base()\n”;
};
};
class D1 :public Base {};
class D2 :public Base
{
public:
D2(void)
{
cout<<”D2()\n”;
}
D2(int_i): Base(i)
{
cout<<”D2(“<<i<<”)\n”;
}
~D2(void)
{
cout<<”~D2()\n”;
}

};
int main(void)
{
D1 a;
D2 b;
D2 c(100);
return 0;
}
a) Base()
Base()
D2()
Base(100)
D2(100)
~D2()
~Base()
~D2()
~Base()
~Base()
b) Syntax error [ANS]
c) runtime error
d)none of these

71. Class Test:public A, public B is an example of——-
a) single inheritance
b) multiple inheritance [ANS]
c) repeated inheritance
d) None of these

72.  Which of the following interface determines how your program will be used by other program?
a) Public [ANS]
b) Private
c) Protected
d) None of these

73. What will output of the following program code?
#include
using namespace std;
class A
{
protected:
int x,y;
public:
void setvalues(int a,int b0
{
x=a; y=b;
}
};

class B
{
public:
void display(int_i)
};
void B::display(int_i)
{
cout<<i<<endl;
}
class C: public A, public B
{
public:
int add()
{
return(x+y+10);
}
};
int main()
{
Cobj1;
Dobj2;
obj1.setvalues(10,20);
obj2.setvalues(10,20);
obj1.display(obj1.add());
obj2.display(obj2.add());
return 0;

}
a) 10 20
b) 30 40 [ANS]
c) 20 40
d) none of these

74. Choose the incorrect function from the following
a) inheritance is a mechanism that inherits the new class from the existing one.
b) we can specify which data members and member function of base class can be inherited by derived class
c) we can add new function to the derived class
d) all the data members and member function of base class can be inherited by the derived class [ANS]

75.  When base class pointer points to derived class object___________
a) it can access only base class members [ANS]
b) it can access only derived class members
c) both base class &derived class members
d) none of these

76.  The base class will offer_____
a) more specific object than the derived class
b) more generalized version of its derived class [ANS]
c) empty templates of its derived class
d) none of these

77. The hybrid inheritance is _____
a) multiple inheritance
b) multilevel inheritance
c) multipath inheritance
d) both a &c [ANS]

78. How many types of inheritance its there
a) 1
b) 2
c) 4
d) 5 [ANS]

79. Choose the correct option
a) a constructor can not be called explicitly
b) a destructor is not inherited
c) constructor can not be inherited
d) All of these [ANS]

80. Suppose class derived is derived from a class Base. Both the classes contain the function name Display() that takes no argument . What will be statement in the class Derived which will called the display() function of base class
a) display()
b) Base:display()
c) Base::display() [ANS]
d) can make such cell

81. Suppose class “Derived” is derived from a class “Base” privately. The object of class “Derived” located in main() can access_______.
a) public members of base
b) private member of base
c) protected members of base
d) public members of derived [ANS]

82. Multiple inheritance causes for a derived class to have ___members.
a) ambiguous [ANS]
b) public
c) private
d) protected

83. What will be the first line of specifier for the class tier, wheel & rubber. Make use of  public rubber
a) Class Tier:public wheel, public rubber [ANS]
b) Class wheel:public tier, public rubber
c) Class rubber:public tier, public wheel
d) none of these

84.  Which is the correct class defination for class C ,Which inherits from A & B Classes
a) Class C:A,B
b) Class C::A,B
c) Class C:public A,public B [ANS]
d) Class C:: public A,Public B

85. The ability of function or operator to act in different ways on different data types is called______
a) inheritance
b) polymorphism [ANS]
c) encapsulation
d) none of these

86. _____class that declares or inherits a virtual function.
a) Encapsulation data
b) Inherited class
c) Polymorphic class [ANS]
d) none of these

87.  Choose the correct option.
a) A base class may have more then one derived class
b) Derived class may have more than one derived class
c) Both a & b [ANS]
d) Neither a nor b

88. Which of the following advantage we lose by using multiple inheritance?
a) Polymorphism
b) Dynamic binding
c) Both a & b [ANS]
d) none of these

89. Overloading is form of______
a) virtual polymorphism
b) transient polymorphism
c) ad-hoc polymorphism
d) none of these

90. The constructor for the derived class must be provided________
a) if base class constructor required arguments [ANS]
b) if base class constructor does not required arguments
c) never
d) always

91. _____ function are bounded dynamically at run time.
a) static
b) friend
c) inline
d) virtual [ANS]

92. A virtual function allows you to________
a) create array of pointer to base class that can hold pointers to derived Classes
b) create function that can never be accessible
c) use same function cell to execute member functions of object from different classes  [ANS]
d) none of these

93.  A pure virtual function is a function that_______
a) causes its class to abstract [ANS]
b) returns nothing
c) takes no argument
d) none of these

94. An abstract class is useful when______
a) no classes should be derived from it
b) there are multiple paths from one derived class to another
c) no objects can be instantiated from it. [ANS]
d) none of these

95. Choose the correct statement.
a) An abstract base class can have pure virtual destructor
b) An abstract base class can have virtual destructor
c) An abstract base class can have non virtual destructor
d) An abstract base class cannot destructor [ANS]

96. The compiler identifies the virtual function to be pure _________.
a) if the keyword pure is present
b) its location in the program
c) if it is equal to 0 [ANS]
d) none of these

97. For appropriate polymorphism mechanism, a method in base class must be declared _.
a) public
b) private
c) protected
d) virtual [ANS]

98. A virtual function is a member function that excepts to be _______ in a derived class.
a) private
b) overridden [ANS]
c) public
d) none of these

99. The keyword virtual indicates that ________.
a) more than one base class exists
b) base class should be used only once in inheritance [ANS]
c) a derived class has public access to base class
d) none of these

100.  Select the correct option.
1. C++ allows multiple inheritance.
2.Polymorphism is achieved by means of virtual functions.
a) Only 1 is true
b) Only 2 is true
c) Both 1 & 2 is true [ANS]
d) Neither 1 nor 2 is true

101.  Select the correct option.
1. A pure virtual is always implemented in the class in which it is declared.
2. An abstract class cannot contain pure virtual function.
a) Only 1 is true
b) Only 2 is true
c) Both 1 & 2 is true
d) Neither 1 nor 2 is true [ANS]

102.  Select the correct option.
1.The keyword abstract is used to define an abstract class.
2. Inheritance allows multi-level class hierarchies beyond two levels also.
a)Only 1 is true
b)Only 2 is true [ANS]
c)Both 1 & 2 is true
d)Neither 1 nor 2 is true