This quiz is completed
Here's a high-difficulty multiple-choice quiz based on your OOP PDF, formatted as requested:
UNIT I: Basic OOP Concepts
1. What is the primary purpose of encapsulation in OOP?
To allow multiple inheritance
To wrap data and functions into a single unit (class)
To enable dynamic memory allocation
To override base class methods
2. Which of the following is not a feature of OOP?
Bottom-up program design
Emphasis on procedures over data
Data abstraction
Message passing
3. Polymorphism allows:
A function to take multiple forms based on input types
A class to inherit from multiple base classes
Data members to be declared as static
Constructors to be overloaded
4. What distinguishes a class from a structure in C++?
Classes cannot have member functions
Structures default to private members, while classes default to public
Classes default to private members, while structures default to public
Structures support inheritance but classes do not
5. Which statement about constructors is false?
They have the same name as the class
They can return values
They are invoked automatically upon object creation
They can be overloaded
UNIT II: Pointers, Functions, and Classes
6. What is the output of the following code?
int x = 10;
int *p = &x;
cout << *p + 1;
10
11
Memory address of
xCompiler error
7. Which storage class specifier ensures a variable persists throughout the program’s execution?
autoregisterstaticextern8. What is the purpose of a
friend function?To allow a function to access private members of a class
To prevent inheritance
To enforce encapsulation
To overload operators
9. Which operator cannot be overloaded in C++?
+::<<[]10. What is the result of
sizeof on an empty class?0
1
Compiler-dependent
Size of the largest member function
UNIT III: Constructors, Destructors, and Operator Overloading
11. A dynamic constructor is used to:
Allocate memory at runtime for objects
Initialize static members
Declare virtual functions
Overload the
= operator12. Which statement about destructors is true?
They can take arguments
They are inherited by derived classes
They are prefixed with a tilde (
~)They can be overloaded
13. What is the output of the following code?
class A {
public:
virtual void show() { cout << "A"; }
};class B : public A { void show() { cout << "B"; }
};
A *a = new B();
a->show();
A
B
Compiler error
Runtime error
14. Which operator overloading requires the function to be a member of the class?
+<<->==15. What is the purpose of the
this pointer?To refer to the current object instance
To allocate dynamic memory
To access static members
To call destructors explicitly
UNIT IV: Inheritance and Polymorphism
16. In hybrid inheritance:
A class inherits from multiple base classes
A combination of multiple inheritance types is used
Constructors are chained automatically
Virtual functions are mandatory
17. An abstract class must have:
At least one pure virtual function
No member functions
All members declared as
privateA destructor with default arguments
18. Which visibility mode preserves
protected members as protected in a derived class?public derivationprivate derivationprotected derivationfriend derivation19. What is the primary advantage of late binding?
Faster compilation
Runtime flexibility in function calls
Reduced memory usage
Simplified syntax
20. Which keyword resolves ambiguity in multiple inheritance?
virtualstaticconstfriendUNIT V: Files and Exception Handling
21. Which file mode opens a file for appending without truncating existing content?
ios::outios::appios::truncios::nocreate22. What does
seekg() do?Moves the put pointer
Moves the get pointer
Deletes file content
Closes a file stream
23. Which exception handling block executes regardless of whether an exception occurs?
trycatchfinallythrow24. What is the output of the following code?
try {
throw 5;
} catch (char c) { cout << "Char"; }catch (...) { cout << "Default"; }
Char
Default
5
No output
25. Which function checks if a file operation failed due to invalid input?
eof()bad()fail()good()