Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.
You're offline
Unit 4 MCQsOperator Overloading, Type Conversion and Inheritance
Which keyword is used to overload an operator in C++?
Not quite. Try another option.
Answer: operator
The 'operator' keyword is used to declare a function that specifies what a particular operator means when applied to instances of a class.
Question 2 of 50
Which of the following operators CANNOT be overloaded?
Not quite. Try another option.
Answer: ::
The scope resolution operator (::), along with the dot operator (.), ternary operator (?:), and sizeof, cannot be overloaded.
Question 3 of 50
When overloading a binary operator as a member function, how many arguments does the function take?
Not quite. Try another option.
Answer: One
As a member function, a binary operator takes one explicit argument (the right-hand operand); the left-hand operand is passed implicitly via the 'this' pointer.
Question 4 of 50
When overloading a unary operator as a friend function, how many arguments must it take?
Not quite. Try another option.
Answer: One
Since a friend function does not have a 'this' pointer, the operand must be passed explicitly as an argument.
Question 5 of 50
To convert a Basic type to a Class type, which method is primarily used?
Not quite. Try another option.
Answer: Constructor
A constructor taking a single argument of a basic type is used to convert that basic type into the class type.
Question 6 of 50
Which syntax is used to define a conversion function to convert a Class type to a Basic type?
Not quite. Try another option.
Answer: operator type()
The syntax 'operator type()' (e.g., operator int()) is used to define a casting operator function for class-to-basic conversion.
Question 7 of 50
What is the return type specified in the declaration of a casting operator function (e.g., operator int())?
Not quite. Try another option.
Answer: No return type
Casting operator functions do not specify a return type explicitly; the return type is inferred from the operator name itself.
Question 8 of 50
Which relationship does Inheritance primarily model?
Not quite. Try another option.
Answer: Is-A
Inheritance models an 'Is-A' relationship (e.g., a Dog is an Animal).
Question 9 of 50
In the syntax class Derived : access Base, what is the default access mode if none is specified?
Not quite. Try another option.
Answer: private
In C++, the default inheritance mode for classes is private.
Question 10 of 50
Which type of inheritance involves a derived class inheriting from multiple base classes?
Not quite. Try another option.
Answer: Multiple Inheritance
Multiple inheritance occurs when a class is derived from more than one base class.
Question 11 of 50
In public inheritance, public members of the base class become __ in the derived class.
Not quite. Try another option.
Answer: Public
Under public inheritance, public members of the base class retain their public status in the derived class.
Question 12 of 50
In private inheritance, public members of the base class become __ in the derived class.
Not quite. Try another option.
Answer: Private
Under private inheritance, all accessible members (public and protected) of the base class become private in the derived class.
Question 13 of 50
Which members of a base class are never accessible to the derived class directly?
Not quite. Try another option.
Answer: Private members
Private members of a base class are not directly accessible by the derived class, regardless of the inheritance mode.
Question 14 of 50
What is the correct order of constructor execution in Single Inheritance?
Not quite. Try another option.
Answer: Base first, then Derived
Constructors are executed in the order of inheritance: the base class constructor is called first, followed by the derived class constructor.
Question 15 of 50
What is the correct order of destructor execution in Single Inheritance?
Not quite. Try another option.
Answer: Derived first, then Base
Destructors are executed in reverse order of construction: the derived class destructor is called first, followed by the base class destructor.
Question 16 of 50
If class C inherits from class B, and class B inherits from class A, this is an example of:
Not quite. Try another option.
Answer: Multi-level Inheritance
This chain (A -> B -> C) represents Multi-level inheritance.
Question 17 of 50
What is the 'Diamond Problem' in C++ inheritance?
Not quite. Try another option.
Answer: Ambiguity arising from multiple inheritance where two base classes inherit from a common ancestor
The Diamond Problem occurs in multiple inheritance when a class inherits from two classes that both inherit from the same super-base class, causing duplication of the super-base members.
Question 18 of 50
How is the Diamond Problem resolved in C++?
Not quite. Try another option.
Answer: Using Virtual Base Classes
Virtual inheritance ensures that only one copy of the base class members is inherited by the grandchild class.
Question 19 of 50
What distinguishes Function Overriding from Function Overloading?
Not quite. Try another option.
Answer: Overriding happens in derived classes with same signature; Overloading happens in same/derived scope with different signature
Overriding redefines a base class function in a derived class with the exact same signature. Overloading involves functions with the same name but different parameters.
Question 20 of 50
How can a derived class call an overridden member function of the base class?
Not quite. Try another option.
Answer: Base::func()
The scope resolution operator (::) is used to access the overridden function of the base class explicitly.
Question 21 of 50
What does the protected access specifier ensure?
Not quite. Try another option.
Answer: Members are accessible in the class and its derived classes
Protected members are inaccessible outside the class but can be accessed by derived classes.
Question 22 of 50
Which concept represents a 'Has-A' relationship where the child cannot exist without the parent (Strong Association)?
Not quite. Try another option.
Answer: Composition
Composition is a strong 'Has-A' relationship where the lifecycle of the contained object is managed by the container; if the container is destroyed, the contained object is also destroyed.
Question 23 of 50
Which concept represents a 'Has-A' relationship where the child can exist independently of the parent (Weak Association)?
Not quite. Try another option.
Answer: Aggregation
Aggregation implies a relationship where the child object can exist independently of the parent object.
Question 24 of 50
When overloading the increment operator operator++(int), what does the dummy int parameter indicate?
Not quite. Try another option.
Answer: It indicates Postfix increment
The int argument is a dummy flag used by the compiler to distinguish post-increment (++x) from pre-increment (x++).
Question 25 of 50
If class D : public B1, public B2 is defined, which constructor is called first?
Not quite. Try another option.
Answer: B1
In multiple inheritance, base class constructors are called in the order in which they are inherited (declared in the class header).
Question 26 of 50
Which operator is typically overloaded to implement input/output for a user-defined class?
Not quite. Try another option.
Answer: << and >>
The stream insertion (<<) and extraction (>>) operators are overloaded to facilitate I/O for custom classes.
Question 27 of 50
Why must operator<< and operator>> be overloaded as friend functions usually?
Not quite. Try another option.
Answer: Because the left operand is a stream object, not the class object
If they were member functions, the syntax would be object << cout. To support cout << object, the function must be a non-member (usually friend) where the first argument is the stream.
Question 28 of 50
Can a constructor be inherited?
Not quite. Try another option.
Answer: No, constructors are not inherited
Constructors and destructors are not inherited; however, the derived class constructor invokes the base class constructor.
Question 29 of 50
What happens if a derived class defines a function with the same name as a base class function but different arguments?
Not quite. Try another option.
Answer: It hides the base function
This is called name hiding. The base class function becomes hidden in the derived scope unless explicitly brought in with a using declaration.
Question 30 of 50
Which inheritance mode makes public members of the base class protected in the derived class?
Not quite. Try another option.
Answer: protected
Protected inheritance changes public and protected members of the base class to protected in the derived class.
Question 31 of 50
In hierarchical inheritance, how many derived classes exist?
Not quite. Try another option.
Answer: Two or more derived from a single base
Hierarchical inheritance involves a single base class serving as a parent to multiple derived classes.
Question 32 of 50
How do you pass arguments to a base class constructor from a derived class constructor?
Not quite. Try another option.
Answer: Using the Member Initializer List
Arguments are passed to the base constructor using the syntax Derived(args) : Base(args) { ... }.
Question 33 of 50
To prevent a class from being inherited, C++11 introduced which keyword?
Not quite. Try another option.
Answer: final
The final specifier prevents a class from being used as a base class.
Question 34 of 50
What is the return type of the overloaded assignment operator (operator=) generally?
Not quite. Try another option.
Answer: Reference to the class type
It returns a reference to the class type (*this) to allow for chained assignments (e.g., a = b = c).
Question 35 of 50
Which operator cannot be overloaded using a friend function?
Not quite. Try another option.
Answer: =
The assignment operator (=), function call operator (()), subscript operator ([]), and arrow operator (->) must be overloaded as member functions.
Question 36 of 50
If a base class has a private member int x, and class D : public Base, how can D access x?
Not quite. Try another option.
Answer: It cannot access it directly
Private members are never accessible in derived classes. Access must be provided via public/protected getter methods in the base class.
Question 37 of 50
What is the ambiguity resolution operator used in multiple inheritance?
Not quite. Try another option.
Answer: ::
The scope resolution operator (::) is used to specify which base class's member is being accessed (e.g., Base1::print()).
Question 38 of 50
In composition, if the container object is destroyed:
Not quite. Try another option.
Answer: The contained objects are also destroyed
Composition implies ownership; the lifetime of the part is bound to the lifetime of the whole.
Question 39 of 50
Which of the following is true about friend functions and inheritance?
Not quite. Try another option.
Answer: Friendships are not inherited
Friendship is not inherited. A friend of the base class is not automatically a friend of the derived class.
Question 40 of 50
When overloading the subscript operator [], what is it commonly used for?
Not quite. Try another option.
Answer: To access elements of an object as if it were an array
Overloading [] allows objects (like a custom Vector or String class) to be indexed using array syntax.
Question 41 of 50
What is a major advantage of Operator Overloading?
Not quite. Try another option.
Answer: Allows user-defined types to behave like built-in types
It improves code readability and allows custom classes to integrate seamlessly with standard operators.
Question 42 of 50
If a constructor is declared explicit, what does it prevent?
Not quite. Try another option.
Answer: Implicit type conversion
The explicit keyword prevents the compiler from using that constructor for implicit type conversions (e.g., passing an int to a function expecting a Class object).
Question 43 of 50
In a class-to-basic type conversion function, can arguments be passed?
Not quite. Try another option.
Answer: No, it takes no arguments
Conversion functions (e.g., operator double()) take no arguments.
Question 44 of 50
Virtual Base Classes are primarily used to solve ambiguity in which type of inheritance?
Not quite. Try another option.
Answer: Hybrid/Multiple
They are used in multipath (hybrid) inheritance involving multiple inheritance (the Diamond Problem).
Question 45 of 50
Which header file is generally required for standard I/O operator overloading?
Not quite. Try another option.
Answer: <iostream>
<iostream> defines istream and ostream, which are necessary for overloading << and >>.
Question 46 of 50
What is the syntax to declare a virtual base class?
Not quite. Try another option.
Answer: Both A and B
The virtual keyword can be placed before or after the access specifier (e.g., virtual public or public virtual).
Question 47 of 50
In aggregation, the relationship between the Whole and the Part is:
Not quite. Try another option.
Answer: The Part can exist independently of the Whole
Aggregation is a weak relationship (e.g., A Department has Teachers; if the Department closes, Teachers still exist).
Question 48 of 50
What is the main benefit of Inheritance?
Not quite. Try another option.
Answer: Code Reusability
Inheritance allows new classes to reuse code from existing classes, reducing redundancy.
Question 49 of 50
When overloading the function call operator (), how many arguments can it accept?
Not quite. Try another option.
Answer: Any number
The function call operator operator() is unique in that it can be overloaded to accept any number of arguments.
Question 50 of 50
If a class Derived inherits Protectedly from Base, and Base has a public function foo(), can main() call DerivedObj.foo()?
Not quite. Try another option.
Answer: No
Since the inheritance is protected, foo() (which was public in Base) becomes protected in Derived, making it inaccessible to the outside world (like main).
That's unit 4
Answer a few questions and your score shows up here.
Nearly through. Did unit 4 of CSE202 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 4 of CSE202 save you a night before the exam?
Then you can help keep it free for the next batch. Ads cover part of the server bill;
the rest comes out of a student's own pocket: the domain, the storage, and keeping
the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason.
to try again.