Unit 4 - Practice Quiz

CSE202

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

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

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. Zero
B. One
C. Two
D. Three

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

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

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

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

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

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

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

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

8 Which relationship does Inheritance primarily model?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

A. Multiple Inheritance
B. Multi-level Inheritance
C. Hierarchical Inheritance
D. Hybrid 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. Memory leaks in derived classes
D. Private members becoming public

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

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

19 What distinguishes Function Overriding from Function Overloading?

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

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

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

21 What does the protected access specifier ensure?

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

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

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

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

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

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 Prefix increment
C. It indicates Postfix increment
D. It is a syntax error

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

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

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

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

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

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

28 Can a constructor be inherited?

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

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

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

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

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

31 In hierarchical inheritance, how many derived classes exist?

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

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

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

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

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

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

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

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. Using this->x
C. Using Base::x
D. It cannot access it directly

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. The contained objects become null
D. It depends on the destructor

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

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

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

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

41 What is a major advantage of Operator Overloading?

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

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

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

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

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

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

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

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

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

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

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

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

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

48 What is the main benefit of Inheritance?

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

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

A. Zero
B. One
C. Two
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. Yes
B. No
C. Only if foo is virtual
D. Only if Derived is static