Unit 4 - Practice Quiz

CSE202 50 Questions
0 Correct 0 Wrong 50 Left
0/50

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

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

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

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. auto
B. int
C. void
D. No return type

8 Which relationship does Inheritance primarily model?

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

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. Multi-level Inheritance
B. Multiple Inheritance
C. Hierarchical Inheritance
D. Single Inheritance

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

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

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

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

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

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

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

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

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

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

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. Hybrid Inheritance
D. Hierarchical Inheritance

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

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

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

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

19 What distinguishes Function Overriding from Function Overloading?

A. Overriding happens in derived classes with same signature; Overloading happens in same/derived scope with different signature
B. Overriding happens within the same scope; Overloading happens in derived classes
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. parent->func()
B. Base::func()
C. this->func()
D. super.func()

21 What does the protected access specifier ensure?

A. Members are accessible in the class and its derived classes
B. Members are accessible everywhere
C. Members are accessible only within the class
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. Inheritance
B. Composition
C. Association
D. Aggregation

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 indicates Postfix increment
B. It indicates Prefix increment
C. It adds an integer to the object
D. It is a syntax error

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

A. D
B. B2
C. B1
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. + and -
C. new and delete
D. = and ==

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

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

28 Can a constructor be inherited?

A. Only default constructors
B. No, constructors are not inherited
C. Only copy 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 merges with the base function
B. It causes a compile error
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. public
B. virtual
C. private
D. protected

31 In hierarchical inheritance, how many derived classes exist?

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

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

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

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

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

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

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

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. It cannot access it directly
B. Using this->x
C. Using Base::x
D. Directly as 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. It depends on the destructor
B. The contained objects remain in memory
C. The contained objects become null
D. The contained objects are also destroyed

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

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

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

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

41 What is a major advantage of Operator Overloading?

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

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

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

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

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

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

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

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. class B : virtual public A
B. virtual class B : public A
C. class B : public virtual A
D. Both A and B

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

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

48 What is the main benefit of Inheritance?

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

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

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

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

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