1Which keyword is used to overload an operator in C++?
A.override
B.operator
C.overload
D.this
Correct Answer: operator
Explanation:The 'operator' keyword is used to declare a function that specifies what a particular operator means when applied to instances of a class.
Incorrect! Try again.
2Which of the following operators CANNOT be overloaded?
A.+
B.==
C.::
D.[]
Correct Answer: ::
Explanation:The scope resolution operator (::), along with the dot operator (.), ternary operator (?:), and sizeof, cannot be overloaded.
Incorrect! Try again.
3When overloading a binary operator as a member function, how many arguments does the function take?
A.Zero
B.One
C.Two
D.Three
Correct Answer: One
Explanation: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.
Incorrect! Try again.
4When overloading a unary operator as a friend function, how many arguments must it take?
A.Zero
B.One
C.Two
D.Three
Correct Answer: One
Explanation:Since a friend function does not have a 'this' pointer, the operand must be passed explicitly as an argument.
Incorrect! Try again.
5To convert a Basic type to a Class type, which method is primarily used?
A.Casting Operator
B.Constructor
C.Destructor
D.Operator Function
Correct Answer: Constructor
Explanation:A constructor taking a single argument of a basic type is used to convert that basic type into the class type.
Incorrect! Try again.
6Which 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()
Correct Answer: operator type()
Explanation:The syntax 'operator type()' (e.g., operator int()) is used to define a casting operator function for class-to-basic conversion.
Incorrect! Try again.
7What 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
Correct Answer: No return type
Explanation:Casting operator functions do not specify a return type explicitly; the return type is inferred from the operator name itself.
Incorrect! Try again.
8Which relationship does Inheritance primarily model?
A.Has-A
B.Is-A
C.Uses-A
D.Part-Of
Correct Answer: Is-A
Explanation:Inheritance models an 'Is-A' relationship (e.g., a Dog is an Animal).
Incorrect! Try again.
9In the syntax class Derived : access Base, what is the default access mode if none is specified?
A.public
B.private
C.protected
D.internal
Correct Answer: private
Explanation:In C++, the default inheritance mode for classes is private.
Incorrect! Try again.
10Which 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
Correct Answer: Multiple Inheritance
Explanation:Multiple inheritance occurs when a class is derived from more than one base class.
Incorrect! Try again.
11In public inheritance, public members of the base class become __ in the derived class.
A.Public
B.Private
C.Protected
D.Inaccessible
Correct Answer: Public
Explanation:Under public inheritance, public members of the base class retain their public status in the derived class.
Incorrect! Try again.
12In private inheritance, public members of the base class become __ in the derived class.
A.Public
B.Private
C.Protected
D.Inaccessible
Correct Answer: Private
Explanation:Under private inheritance, all accessible members (public and protected) of the base class become private in the derived class.
Incorrect! Try again.
13Which 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
Correct Answer: Private members
Explanation:Private members of a base class are not directly accessible by the derived class, regardless of the inheritance mode.
Incorrect! Try again.
14What is the correct order of constructor execution in Single Inheritance?
A.Derived first, then Base
B.Base first, then Derived
C.Simultaneous
D.Random
Correct Answer: Base first, then Derived
Explanation:Constructors are executed in the order of inheritance: the base class constructor is called first, followed by the derived class constructor.
Incorrect! Try again.
15What is the correct order of destructor execution in Single Inheritance?
A.Derived first, then Base
B.Base first, then Derived
C.Simultaneous
D.Random
Correct Answer: Derived first, then Base
Explanation:Destructors are executed in reverse order of construction: the derived class destructor is called first, followed by the base class destructor.
Incorrect! Try again.
16If 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
Correct Answer: Multi-level Inheritance
Explanation:This chain (A -> B -> C) represents Multi-level inheritance.
Incorrect! Try again.
17What 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
Correct Answer: Ambiguity arising from multiple inheritance where two base classes inherit from a common ancestor
Explanation: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.
Incorrect! Try again.
18How is the Diamond Problem resolved in C++?
A.Using static classes
B.Using Virtual Base Classes
C.Using friend functions
D.Using abstract classes
Correct Answer: Using Virtual Base Classes
Explanation:Virtual inheritance ensures that only one copy of the base class members is inherited by the grandchild class.
Incorrect! Try again.
19What 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
Correct Answer: Overriding happens in derived classes with same signature; Overloading happens in same/derived scope with different signature
Explanation: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.
Incorrect! Try again.
20How 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()
Correct Answer: Base::func()
Explanation:The scope resolution operator (::) is used to access the overridden function of the base class explicitly.
Incorrect! Try again.
21What 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
Correct Answer: Members are accessible in the class and its derived classes
Explanation:Protected members are inaccessible outside the class but can be accessed by derived classes.
Incorrect! Try again.
22Which concept represents a 'Has-A' relationship where the child cannot exist without the parent (Strong Association)?
A.Aggregation
B.Composition
C.Inheritance
D.Association
Correct Answer: Composition
Explanation: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.
Incorrect! Try again.
23Which 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
Correct Answer: Aggregation
Explanation:Aggregation implies a relationship where the child object can exist independently of the parent object.
Incorrect! Try again.
24When 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
Correct Answer: It indicates Postfix increment
Explanation:The int argument is a dummy flag used by the compiler to distinguish post-increment (++x) from pre-increment (x++).
Incorrect! Try again.
25If 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
Correct Answer: B1
Explanation:In multiple inheritance, base class constructors are called in the order in which they are inherited (declared in the class header).
Incorrect! Try again.
26Which operator is typically overloaded to implement input/output for a user-defined class?
A.+ and -
B.new and delete
C.<< and >>
D.= and ==
Correct Answer: << and >>
Explanation:The stream insertion (<<) and extraction (>>) operators are overloaded to facilitate I/O for custom classes.
Incorrect! Try again.
27Why 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
Correct Answer: Because the left operand is a stream object, not the class object
Explanation: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.
Incorrect! Try again.
28Can a constructor be inherited?
A.Yes, always
B.No, constructors are not inherited
C.Only default constructors
D.Only copy constructors
Correct Answer: No, constructors are not inherited
Explanation:Constructors and destructors are not inherited; however, the derived class constructor invokes the base class constructor.
Incorrect! Try again.
29What 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
Correct Answer: It hides the base function
Explanation:This is called name hiding. The base class function becomes hidden in the derived scope unless explicitly brought in with a using declaration.
Incorrect! Try again.
30Which inheritance mode makes public members of the base class protected in the derived class?
A.public
B.private
C.protected
D.virtual
Correct Answer: protected
Explanation:Protected inheritance changes public and protected members of the base class to protected in the derived class.
Incorrect! Try again.
31In 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
Correct Answer: Two or more derived from a single base
Explanation:Hierarchical inheritance involves a single base class serving as a parent to multiple derived classes.
Incorrect! Try again.
32How 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
Correct Answer: Using the Member Initializer List
Explanation:Arguments are passed to the base constructor using the syntax Derived(args) : Base(args) { ... }.
Incorrect! Try again.
33To prevent a class from being inherited, C++11 introduced which keyword?
A.stop
B.static
C.final
D.const
Correct Answer: final
Explanation:The final specifier prevents a class from being used as a base class.
Incorrect! Try again.
34What 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
Correct Answer: Reference to the class type
Explanation:It returns a reference to the class type (*this) to allow for chained assignments (e.g., a = b = c).
Incorrect! Try again.
35Which operator cannot be overloaded using a friend function?
A.+
B.-
C.=
D.==
Correct Answer: =
Explanation:The assignment operator (=), function call operator (()), subscript operator ([]), and arrow operator (->) must be overloaded as member functions.
Incorrect! Try again.
36If 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
Correct Answer: It cannot access it directly
Explanation:Private members are never accessible in derived classes. Access must be provided via public/protected getter methods in the base class.
Incorrect! Try again.
37What is the ambiguity resolution operator used in multiple inheritance?
A..
B.->
C.::
D.*
Correct Answer: ::
Explanation:The scope resolution operator (::) is used to specify which base class's member is being accessed (e.g., Base1::print()).
Incorrect! Try again.
38In 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
Correct Answer: The contained objects are also destroyed
Explanation:Composition implies ownership; the lifetime of the part is bound to the lifetime of the whole.
Incorrect! Try again.
39Which 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
Correct Answer: Friendships are not inherited
Explanation:Friendship is not inherited. A friend of the base class is not automatically a friend of the derived class.
Incorrect! Try again.
40When 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
Correct Answer: To access elements of an object as if it were an array
Explanation:Overloading [] allows objects (like a custom Vector or String class) to be indexed using array syntax.
Incorrect! Try again.
41What 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
Correct Answer: Allows user-defined types to behave like built-in types
Explanation:It improves code readability and allows custom classes to integrate seamlessly with standard operators.
Incorrect! Try again.
42If a constructor is declared explicit, what does it prevent?
A.Inheritance
B.Implicit type conversion
C.Object destruction
D.Overloading
Correct Answer: Implicit type conversion
Explanation: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).
Incorrect! Try again.
43In 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
Correct Answer: No, it takes no arguments
Explanation:Conversion functions (e.g., operator double()) take no arguments.
Incorrect! Try again.
44Virtual Base Classes are primarily used to solve ambiguity in which type of inheritance?
A.Single
B.Multilevel
C.Hierarchical
D.Hybrid/Multiple
Correct Answer: Hybrid/Multiple
Explanation:They are used in multipath (hybrid) inheritance involving multiple inheritance (the Diamond Problem).
Incorrect! Try again.
45Which header file is generally required for standard I/O operator overloading?
A.<iostream>
B.<conio.h>
C.<fstream>
D.<stdlib.h>
Correct Answer: <iostream>
Explanation:<iostream> defines istream and ostream, which are necessary for overloading << and >>.
Incorrect! Try again.
46What 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
Correct Answer: Both A and B
Explanation:The virtual keyword can be placed before or after the access specifier (e.g., virtual public or public virtual).
Incorrect! Try again.
47In 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
Correct Answer: The Part can exist independently of the Whole
Explanation:Aggregation is a weak relationship (e.g., A Department has Teachers; if the Department closes, Teachers still exist).
Incorrect! Try again.
48What is the main benefit of Inheritance?
A.Encapsulation
B.Code Reusability
C.Data Hiding
D.Operator Overloading
Correct Answer: Code Reusability
Explanation:Inheritance allows new classes to reuse code from existing classes, reducing redundancy.
Incorrect! Try again.
49When overloading the function call operator (), how many arguments can it accept?
A.Zero
B.One
C.Two
D.Any number
Correct Answer: Any number
Explanation:The function call operator operator() is unique in that it can be overloaded to accept any number of arguments.
Incorrect! Try again.
50If 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
Correct Answer: No
Explanation:Since the inheritance is protected, foo() (which was public in Base) becomes protected in Derived, making it inaccessible to the outside world (like main).
Incorrect! Try again.
Give Feedback
Help us improve by sharing your thoughts or reporting issues.