Unit 4: Operator Overloading, Type Conversion and Inheritance - Practice Quiz

CSE202 — Object Oriented Programming 50 Questions
0 Correct 0 Wrong 50 Left
0/50

1 Which keyword is used to overload an operator in C++?

A. this
B. operator
C. override
D. overload

2 Which of the following operators CANNOT be overloaded?

A. []
B. +
C. ==
D. ::

3 When overloading a binary operator as a member function, how many arguments does the function take?

A. One
B. Two
C. Three
D. Zero

4 When overloading a unary operator as a friend function, how many arguments must it take?

A. Two
B. One
C. Zero
D. Three

5 To convert a Basic type to a Class type, which method is primarily used?

A. Destructor
B. Casting Operator
C. Operator Function
D. Constructor

6 Which syntax is used to define a conversion function to convert a Class type to a Basic type?

A. type operator()
B. to type()
C. operator type()
D. conversion type()

7 What is the return type specified in the declaration of a casting operator function (e.g., operator int())?

A. No return type
B. void
C. int
D. auto

8 Which relationship does Inheritance primarily model?

A. Uses-A
B. Is-A
C. Part-Of
D. Has-A

9 In the syntax class Derived : access Base, what is the default access mode if none is specified?

A. private
B. protected
C. public
D. internal

10 Which type of inheritance involves a derived class inheriting from multiple base classes?

A. Multi-level Inheritance
B. Hierarchical Inheritance
C. Single Inheritance
D. Multiple Inheritance

11 In public inheritance, public members of the base class become __ in the derived class.

A. Inaccessible
B. Public
C. Protected
D. Private

12 In private inheritance, public members of the base class become __ in the derived class.

A. Inaccessible
B. Private
C. Protected
D. Public

13 Which members of a base class are never accessible to the derived class directly?

A. Static members
B. Protected members
C. Public members
D. Private members

14 What is the correct order of constructor execution in Single Inheritance?

A. Simultaneous
B. Derived first, then Base
C. Base first, then Derived
D. Random

15 What is the correct order of destructor execution in Single Inheritance?

A. Simultaneous
B. Base first, then Derived
C. Derived first, then Base
D. Random

16 If class C inherits from class B, and class B inherits from class A, this is an example of:

A. Multi-level Inheritance
B. Hybrid Inheritance
C. Hierarchical Inheritance
D. Multiple Inheritance

17 What is the 'Diamond Problem' in C++ inheritance?

A. Circular dependency errors
B. Ambiguity arising from multiple inheritance where two base classes inherit from a common ancestor
C. Private members becoming public
D. Memory leaks in derived classes

18 How is the Diamond Problem resolved in C++?

A. Using Virtual Base Classes
B. Using abstract classes
C. Using friend functions
D. Using static classes

19 What distinguishes Function Overriding from Function Overloading?

A. Overriding requires different return types
B. Overloading uses the virtual keyword
C. Overriding happens within the same scope; Overloading happens in derived classes
D. Overriding happens in derived classes with same signature; Overloading happens in same/derived scope with different signature

20 How can a derived class call an overridden member function of the base class?

A. Base::func()
B. super.func()
C. parent->func()
D. this->func()

21 What does the protected access specifier ensure?

A. Members are accessible in the class and its derived classes
B. Members are accessible only within the class
C. Members are accessible only to friend functions
D. Members are accessible everywhere

22 Which concept represents a 'Has-A' relationship where the child cannot exist without the parent (Strong Association)?

A. Association
B. Aggregation
C. Inheritance
D. Composition

23 Which concept represents a 'Has-A' relationship where the child can exist independently of the parent (Weak Association)?

A. Aggregation
B. Encapsulation
C. Composition
D. Inheritance

24 When overloading the increment operator operator++(int), what does the dummy int parameter indicate?

A. It adds an integer to the object
B. It indicates Postfix increment
C. It indicates Prefix increment
D. It is a syntax error

25 If class D : public B1, public B2 is defined, which constructor is called first?

A. B1
B. B2
C. It depends on the initializer list
D. D

26 Which operator is typically overloaded to implement input/output for a user-defined class?

A. = and ==
B. << and >>
C. + and -
D. new and delete

27 Why must operator<< and operator>> be overloaded as friend functions usually?

A. Because they are static
B. Because the left operand is a stream object, not the class object
C. Because they modify private data
D. Because they return void

28 Can a constructor be inherited?

A. No, constructors are not inherited
B. Only copy constructors
C. Only default constructors
D. Yes, always

29 What happens if a derived class defines a function with the same name as a base class function but different arguments?

A. It causes a compile error
B. It merges with the base function
C. It hides the base function
D. It overrides the base function

30 Which inheritance mode makes public members of the base class protected in the derived class?

A. protected
B. public
C. virtual
D. private

31 In hierarchical inheritance, how many derived classes exist?

A. Two or more derived from a single base
B. A chain of derived classes
C. Exactly one
D. One derived from multiple bases

32 How do you pass arguments to a base class constructor from a derived class constructor?

A. It is handled automatically
B. Using the Member Initializer List
C. Inside the constructor body
D. Using the super keyword

33 To prevent a class from being inherited, C++11 introduced which keyword?

A. static
B. const
C. final
D. stop

34 What is the return type of the overloaded assignment operator (operator=) generally?

A. void
B. int
C. The class type by value
D. Reference to the class type

35 Which operator cannot be overloaded using a friend function?

A. -
B. +
C. =
D. ==

36 If a base class has a private member int x, and class D : public Base, how can D access x?

A. Directly as x
B. It cannot access it directly
C. Using this->x
D. Using Base::x

37 What is the ambiguity resolution operator used in multiple inheritance?

A. .
B. ->
C. ::
D. *

38 In composition, if the container object is destroyed:

A. The contained objects remain in memory
B. The contained objects are also destroyed
C. It depends on the destructor
D. The contained objects become null

39 Which of the following is true about friend functions and inheritance?

A. Friends become public members
B. Friendships are inherited
C. Friendships are not inherited
D. Derived classes automatically befriend the base's friends

40 When overloading the subscript operator [], what is it commonly used for?

A. To access elements of an object as if it were an array
B. To modify the inheritance mode
C. To cast types
D. To create arrays of objects

41 What is a major advantage of Operator Overloading?

A. Enables multiple inheritance
B. Increases execution speed
C. Reduces memory usage
D. Allows user-defined types to behave like built-in types

42 If a constructor is declared explicit, what does it prevent?

A. Implicit type conversion
B. Object destruction
C. Inheritance
D. Overloading

43 In a class-to-basic type conversion function, can arguments be passed?

A. Yes, multiple arguments
B. No, it takes no arguments
C. Yes, one argument
D. Only default arguments

44 Virtual Base Classes are primarily used to solve ambiguity in which type of inheritance?

A. Hybrid/Multiple
B. Multilevel
C. Hierarchical
D. Single

45 Which header file is generally required for standard I/O operator overloading?

A. <conio.h>
B. <iostream>
C. <stdlib.h>
D. <fstream>

46 What is the syntax to declare a virtual base class?

A. Both A and B
B. class B : public virtual A
C. virtual class B : public A
D. class B : virtual public A

47 In aggregation, the relationship between the Whole and the Part is:

A. The Whole inherits from the Part
B. The Whole is a friend of the Part
C. The Part cannot exist without the Whole
D. The Part can exist independently of the Whole

48 What is the main benefit of Inheritance?

A. Code Reusability
B. Operator Overloading
C. Encapsulation
D. Data Hiding

49 When overloading the function call operator (), how many arguments can it accept?

A. Two
B. Zero
C. One
D. Any number

50 If a class Derived inherits Protectedly from Base, and Base has a public function foo(), can main() call DerivedObj.foo()?

A. Only if Derived is static
B. Yes
C. Only if foo is virtual
D. No