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

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

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

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

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

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

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

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

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

8 Which relationship does Inheritance primarily model?

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

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

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

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

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

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

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

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

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

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

A. Protected members
B. Public members
C. Static 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. 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. Hierarchical Inheritance
B. Multi-level Inheritance
C. Hybrid Inheritance
D. Multiple Inheritance

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

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

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

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

19 What distinguishes Function Overriding from Function Overloading?

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

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 only to friend functions
B. Members are accessible everywhere
C. Members are accessible in the class and its derived classes
D. Members are accessible only within the class

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

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

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

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

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

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. << and >>
C. = and ==
D. new and delete

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

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

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 hides the base function
B. It overrides the base function
C. It causes a compile error
D. It merges with the base function

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

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

31 In hierarchical inheritance, how many derived classes exist?

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

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

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

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

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

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

A. void
B. Reference to the class type
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. Using this->x
B. Directly as x
C. It cannot access it directly
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 are also destroyed
B. The contained objects remain in memory
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. Friendships are inherited
B. Friends become public members
C. Derived classes automatically befriend the base's friends
D. Friendships are not 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 create arrays of objects
D. To access elements of an object as if it were an array

41 What is a major advantage of Operator Overloading?

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

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

A. Inheritance
B. Object destruction
C. Implicit type conversion
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. Multilevel
B. Single
C. Hierarchical
D. Hybrid/Multiple

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

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

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

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

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 Part cannot exist without the Whole
D. The Whole inherits from the Part

48 What is the main benefit of Inheritance?

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

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