Contents
Phase 1.1 β Topic Frequency & Weightage Breakdown
Based on question-count analysis across Sections A, B and C of the August 2018, December 2018, August 2019, May/June 2022, April/May 2023, June/July 2024, September 2024 and January 2025 COMP 116 papers.
| # | Topic | Approx. Weightage | Priority | Where it shows up |
| 1 | Inheritance (types, access specifiers, virtual base class, diamond problem, ctor/dtor order) | ~20% | TIER 1 | Sec A (every paper, 2β4 Qs), Sec B, Sec C long programs |
| 2 | Constructors & Destructors (types, copy ctor, initialization, order of calls) | ~15% | TIER 1 | Sec A every paper, Sec B theory Q, Sec C programs |
| 3 | Virtual Functions / Pure Virtual / Abstract Classes / Runtime Polymorphism | ~13% | TIER 1 | Sec A, Sec C β the "big program" question almost every year |
| 4 | Operator Overloading (rules, friend-based, unary ++/--) | ~13% | TIER 1 | Sec A, Sec B/C program question (very frequent) |
| 5 | Templates (function template, class template, generic programming) | ~10% | TIER 2 | Sec A, Sec B (near-guaranteed 4-mark question) |
| 6 | Exception Handling (try/catch/throw, rethrow) | ~8% | TIER 2 | Sec A, Sec B short note |
| 7 | Friend Functions | ~7% | TIER 2 | Sec A, used inside operator overloading answers |
| 8 | Static Data Members / Static Functions | ~6% | TIER 2 | Sec A, occasional Sec B program |
| 9 | Core OOP Pillars (Encapsulation, Abstraction, Data Hiding, Composition) | ~5% | TIER 2 | Sec A conceptual MCQs, Sec B intro question |
| 10 | Function Overloading vs Function Overriding | ~3% | TIER 3 | Sec A, occasional Sec C "differentiate" sub-part |
| 11 | Inline Functions | ~3% | TIER 3 | Sec A, Sec B short question |
| 12 | References vs Pointers, pass-by-reference | ~2% | TIER 3 | Sec A |
| 13 | new/delete operator, dynamic memory | ~2% | TIER 3 | Sec A, Sec B short note |
Bottom line: Inheritance + Constructors/Destructors + Virtual Functions/Polymorphism + Operator Overloading together make up roughly 61% of total marks across every past paper. These four topics are non-negotiable β master them first.
Phase 1.2 β Most Repeated Questions & High-Probability Predictions
A. Verbatim / Rephrased Recurring Questions (appeared in 3+ papers)
| Recurring Question Pattern | Seen In | Marks |
| "Create a class hierarchy: base class + 2 derived classes + 1 further-derived class. Implement runtime polymorphism using virtual functions, with data stored in an array of objects." (Province / PublicationβBookβTape / FoodβTableInfoβBillAmount / ReferenceBookβIssuableBook / Digital Wallet / EmployeeβHOD) | 2019, 2022, 2023, 2024(Sept) | 8 |
| "Explain the rules of constructor calls in inheritance. How is a base class data member initialized from a derived class constructor?" | 2018, 2019, 2022, 2023, 2025 | 2β4 |
| "Write a program to overload the (unary ++/-- or binary +) operator using a friend function." | 2018, 2019, 2022, 2023, 2025 | 4β8 |
| "Write a class/function template that returns the largest and/or average value of elements in an array." | 2018, 2019, 2022, 2023, 2024 | 4 |
| "What is a pure virtual function? What are the implications of making a function pure virtual? / What is an abstract class?" | 2018, 2022, 2023, 2024(Sept) | 2β4 |
| "Differentiate between virtual base class and virtual function." / "What sort of ambiguity is solved by virtual base class? Explain with diagram." (Diamond problem) | 2018, 2022, 2023 | 4β8 |
| "Write short notes on (choose 2): Re-throwing an exception / new-delete operator / reference variable / friend function / abstract class" | 2018, 2019, 2022, 2025 | 4 |
| "Write in brief about static data member and static member function of a class." / "Implement a static counter that assigns a serial number to each object created." | 2018, 2022, 2024 | 4 |
| "Differentiate Object-Oriented Programming with Structured/Procedural Programming." | 2019, 2022, 2024, 2025 | 2β4 |
| "Explain the two levels of access control/specifiers over class members in inheritance." | 2018, 2019, 2023, 2024 | 4 |
B. High-Probability Predicted Questions for the Next Exam
1. A Section-C program combining inheritance + operator overloading in one class (e.g., "Length" class adding feet/inches, or a Date/Time class) β this exact pattern has repeated with only cosmetic changes to the domain (province β food bill β book β wallet β employee). Expect a new domain wrapped around the same skeleton: Abstract base class β 2 derived classes β array of objects β runtime polymorphism via base class pointer/reference.
2. "What is the difference between compile-time and run-time polymorphism? Explain each with an example program." β asked as MCQ almost every year, likely to appear as a full Section C sub-question soon.
3. A "trace the output" MCQ testing default arguments, reference parameters, or increment operators (appears in nearly every Section A).
4. Function template with multiple template parameters (template<class T1, class T2>) β asked explicitly in Apr/May 2023.
5. A conceptual "Write in brief" question on generic programming and templates, likely paired with a small class-template code question.
Phase 1.3 β In-Depth High-Yield Notes
1. Core OOP Pillars
| Concept | Definition |
| Encapsulation | Binding data + functions that operate on that data into a single unit (class), restricting direct access to internal state. |
| Abstraction | Showing only essential features while hiding implementation/background details (e.g., pure virtual functions, abstract classes). |
| Inheritance | Mechanism where a new class (derived) acquires properties/behavior of an existing class (base) β enables code reusability. |
| Polymorphism | "Many forms" β same interface, different implementations. Compile-time (function/operator overloading) vs Run-time (virtual functions). |
| Composition | "Has-a" relationship β one class contains an object of another class as a member (object inside object). |
2. Constructors & Destructors
Types of constructors: Default, Parameterized, Copy Constructor, Constructor with default arguments.
Destructor: Special member function, same name as class prefixed with ~, no return type, no arguments, cannot be overloaded β automatically invoked when object goes out of scope / is deallocated.
class A {
int x;
public:
A() { x = 0; } // default constructor
A(int v) { x = v; } // parameterized
A(const A &obj) { x = obj.x; } // copy constructor
~A() { } // destructor
};
Constructor call order in inheritance: Base class constructor is called first (in the order of declaration/inheritance), then the derived class constructor. Virtual base class constructors are called before any non-virtual base classes, regardless of inheritance order.
Initializing base class data via derived constructor β use the member-initializer list:
class Derived : public Base {
public:
Derived(int a, int b) : Base(a) { // Base(a) initializes base part
y = b;
}
};
Destructor call order: exactly reverse of constructor order β derived class destructor runs first, then base class destructor(s).
Copy constructor pitfall: the compiler-generated (default) copy constructor does a shallow copy. If a class has a pointer data member (e.g., dynamically allocated array), shallow copy makes two objects point to the same memory β a deep copy (user-defined copy constructor) is required.
3. Inheritance
| Access Specifier of Inheritance | Public members of Base become | Protected members of Base become | Private members of Base |
class D : public B | Public in D | Protected in D | Inherited but inaccessible directly |
class D : protected B | Protected in D | Protected in D | Inherited but inaccessible directly |
class D : private B (default for class) | Private in D | Private in D | Inherited but inaccessible directly |
Types of inheritance: Single, Multilevel, Multiple, Hierarchical, Hybrid.
Diamond Problem: occurs in multiple/hybrid inheritance when two base classes inherit from the same grandparent, and a class inherits from both β the grandparent's members get duplicated ("ambiguity"). Solved using a virtual base class:
class Person { };
class Account : virtual public Person { };
class Admin : virtual public Person { };
class Master : public Account, public Admin { }; // only ONE copy of Person
With a virtual base class, its constructor is invoked only once, and it is called by the most-derived class β not by the intermediate classes.
4. Virtual Functions, Pure Virtual Functions & Abstract Classes
A virtual function is declared in the base class using the virtual keyword and redefined (overridden) in derived classes; it enables run-time polymorphism resolved via dynamic binding (using base class pointer/reference).
A pure virtual function: virtual void show() = 0; β has no body in the base class. Any class containing at least one pure virtual function becomes an abstract class and cannot be instantiated directly; it can only be used as a base class, and its derived classes must override the pure virtual function (else they remain abstract too).
class Shape { // abstract class
public:
virtual float area() = 0; // pure virtual function
};
class Circle : public Shape {
float r;
public:
Circle(float rad): r(rad) {}
float area() override { return 3.14*r*r; }
};
int main(){
Shape *s = new Circle(5); // base ptr -> derived obj
cout << s->area(); // runtime polymorphism
}
Static (early) binding = function call resolved at compile time (normal function calls, overloading). Dynamic (late) binding = resolved at run time via virtual functions and base class pointers.
5. Operator Overloading
Giving additional/special meaning to existing C++ operators for user-defined types. Can be done as a member function or a friend function.
| Aspect | Member Function | Friend Function |
| Argument count for binary op | 1 explicit argument (left operand is this) | 2 explicit arguments (one more than member function) |
| Access | Direct access to private members | Needs friend declaration to access private members |
| When required | Left operand must be an object of the class | Useful when left operand is NOT of the class type (e.g., 5 + obj) |
class Point {
int x, y;
public:
Point(int a=0,int b=0):x(a),y(b){}
friend Point operator+(const Point &p1, const Point &p2){
return Point(p1.x+p2.x, p1.y+p2.y);
}
// Prefix ++ (member): Point operator++();
// Postfix ++ (member): Point operator++(int); // dummy int marks postfix
};
Operators that CANNOT be overloaded: :: (scope resolution), . (member access), .* (pointer-to-member), ?: (conditional/ternary), sizeof.
6. Templates (Generic Programming)
Templates let you write a single function/class that works with any data type β achieving generic programming.
template<class T>
T maxVal(T a, T b){
return (a > b) ? a : b;
}
// Multiple template parameters:
template<class T1, class T2>
void show(T1 a, T2 b){ cout<<a<<" "<<b; }
template<class T>
class Box {
T value;
public:
void set(T v){ value = v; }
T get(){ return value; }
};
// defining member function OUTSIDE the class:
template<class T>
void Box<T>::set(T v){ value = v; }
7. Exception Handling
try {
if(x==0) throw runtime_error("divide by zero");
}
catch(runtime_error &e){
cout<<e.what();
throw; // re-throw: passes the SAME exception up to an outer handler
}
Rethrowing: done using the bare keyword throw; (no operand) inside a catch block β it forwards the currently-caught exception to an outer/enclosing try-catch block instead of handling it locally.
To catch a thrown C-string literal, the catch clause must match its exact type: catch(const char *s).
8. Friend Functions
A friend function is not a member of the class but is granted access to its private and protected members. Declared inside the class with the friend keyword but defined outside (no scope-resolution operator needed since it isn't a member).
Key rule: Friendship is not inherited and not transitive β if class B is a friend of class A, and C is a friend of B, C is not automatically a friend of A.
9. Static Data Members & Static Functions
class Counter {
static int count; // declaration inside class
public:
Counter(){ count++; }
static int getCount(){ return count; } // static member fn
};
int Counter::count = 0; // definition OUTSIDE class β mandatory
// Access: Counter::getCount(); (no object needed)
A static member function can only directly access other static members of the class (it has no this pointer).
10. Function Overloading vs Overriding
| Function Overloading | Function Overriding |
| Same function name, different parameter list, same class | Same function signature, redefined in derived class |
| Compile-time (static) polymorphism | Run-time (dynamic) polymorphism β needs virtual |
11. Inline Functions
Requested with the inline keyword; the compiler replaces the function call with the function body directly (like a macro), avoiding call-overhead. Faster execution, but larger compiled program size (more memory). Best for small, frequently-used functions β not recommended for large/complex functions with loops or recursion (compiler will usually ignore the request).
Phase 1.4 β Common Pitfalls Table
| Mistake | Why Marks Are Lost | Exact Fix |
| Forgetting the member-initializer list when a base class needs arguments in its constructor | Program won't compile if base class has no default constructor | Always write Derived(args): Base(args) { ... } |
Declaring destructor as ~ClassName(int) or giving it a return type | Destructors can never take arguments or return a value β this is a syntax error | Use exactly ~ClassName(){ } |
| Overloading operator as a member function when the left operand isn't an object of the class | Compiler cannot resolve 5 + obj using a member function | Use a friend function with 2 explicit parameters |
Missing virtual keyword on base class function meant to be overridden | Causes static binding β wrong function called via base pointer (loses all runtime-polymorphism marks) | Always mark the base function virtual; use = 0 for pure virtual |
| Trying to instantiate an abstract class directly | Compile error β abstract classes cannot be instantiated | Only create objects of the fully-derived (non-abstract) class |
Diamond inheritance without virtual on the shared base | Grandparent class gets duplicated β ambiguous member access error | Inherit the common base as virtual public Base in both intermediate classes |
| Defining the static member variable only inside the class | Linker error: "undefined reference" β declaration inside class isn't a definition | Add int ClassName::staticVar = 0; outside the class, once |
| Forgetting to define the copy constructor for a class with pointer members | Shallow copy β double-free / dangling pointer crash, loses "deep copy" marks | Write a custom copy constructor that allocates new memory and copies values |
| Postfix vs prefix operator overload signature confusion | Examiner explicitly checks the int dummy parameter for postfix | Prefix: operator++(). Postfix: operator++(int) |
Writing template function definitions inside .cpp without template<class T> repeated before each out-of-class definition | Linker/compiler error β every template member definition needs its own template header | Repeat template<class T> ReturnType ClassName<T>::func(){} for every method |
| Catching exceptions by value for large/user objects instead of by reference | Unnecessary copy overhead; slicing problem for polymorphic exception hierarchies | Prefer catch(const ExceptionType &e) |
| Confusing "rethrow" with throwing a brand-new exception | Loses marks for not understanding that bare throw; preserves the original exception | Use plain throw; (no operand) inside the catch block to rethrow |
| Not answering the "differentiate" sub-parts with a two-column comparison | Markers award partial credit per point of distinction β a paragraph answer loses these discrete points | Always answer differentiate/compare questions in a two-column table format |
Phase 2 β Master MCQ Practice Bank
All questions are drawn from or adapted from the 8 analyzed past papers, grouped by topic, with the correct option highlighted and a full explanation beneath each card.
Topic: Core OOP Concepts
Q1OOP Basics
Object oriented programming gives priority to ____ of data.
- A. characteristics
- B. Data (over function/operations)
- C. operations only
- D. behaviour
Answer: B. Unlike procedural/structured programming (which emphasizes functions), OOP emphasizes data β data is treated as a critical element and functions operate around the data (encapsulated together in objects).
Q2OOP Basics
The act of representing essential features without including background details is called ____.
- A. Abstraction
- B. Encapsulation
- C. Polymorphism
- D. Inheritance
Answer: A. Abstraction focuses only on relevant/essential characteristics of an object, hiding unnecessary implementation detail from the user.
Q3OOP Basics
What is "composition" in OOP?
- A. Object inside object (generic)
- B. Class inside class (definition)
- C. Object as member of a class
- D. Class as member of object
Answer: C. Composition = "has-a" relationship, implemented by making an object of one class a data member of another class.
Q4OOP Basics
C++ emphasis is on _______ rather than _______.
- A. data, function
- B. function, data
- C. function, loop
- D. function, array
Answer: A. C++ (OOP) emphasizes data over function/procedure, the reverse of procedural languages like C.
Topic: Constructors & Destructors
Q5Constructors
Point p1=3, p2(5), p3(p1), p4; β Which two objects invoke the same constructor?
- A. p4 and p2
- B. p4 and p1
- C. p3 and p2
- D. p1 and p2
Answer: D. p1=3 uses copy-initialization via the single-int-argument constructor; p2(5) directly calls the same single-int-argument constructor. p3(p1) invokes the copy constructor; p4 invokes the default constructor.
Q6Constructors
How do we define a destructor for a class A?
- A. A~(){ }
- B. ~A(){ }
- C. A(){ }~
- D. A()~{ }
Answer: B. Destructor syntax is exactly ~ClassName(){ } β tilde immediately before the class name, no parameters, no return type.
Q7Constructors
Copy constructor may not work properly (shallow copy problem) when the object's data member contains a ____.
- A. Array (fixed-size)
- B. Numerical value
- C. Structure
- D. Pointer / reference (dynamically allocated memory)
Answer: D. The default (compiler-generated) copy constructor performs a shallow copy β pointer members end up pointing to the same memory in both objects, causing double-free / dangling pointer bugs. A user-defined "deep copy" constructor is required.
Q8Constructors
Consider: class C : public B, public A {...}; What is the order of constructor invocation when an object of C is instantiated?
- A. first B(), then A(), then C()
- B. only C() is invoked
- C. first C(), then B(), then A()
- D. first A(), then B(), then C()
Answer: A. Base class constructors are called in the order they are listed in the inheritance declaration (B before A here), and the derived class's own constructor body runs last.
Q9Constructors
Which statement about constructors for virtual base classes is CORRECT?
- A. Base class constructors get invoked in declared order, then derived class, always
- B. Constructors for virtual base classes are invoked before any non-virtual base classes
- C. Both A and B
- D. None
Answer: B. Regardless of the order in which base classes are listed, C++ guarantees virtual base class constructors run first, and only once β called by the most-derived class.
Topic: Inheritance
Q10Inheritance
If class A publicly inherits class B (class A : public B), then:
- A. Public members of B become public members of A
- B. Public members of B become private members of A
- C. Protected members of B become public members of A
- D. Private members of B become public members of A
Answer: A. Public inheritance preserves access levels: public stays public, protected stays protected. Private members of B are inherited but remain inaccessible directly in A regardless of the inheritance mode.
Q11Inheritance
In C++, inheritance primarily exhibits a ____ relationship.
- A. Has-A
- B. Is-A
- C. Association
- D. Composition
Answer: B. Inheritance models "Is-A" (e.g., a Doctor is a Person). Composition/aggregation model "Has-A".
Q12Inheritance
Which of the following operator prototype is the CORRECT post-increment overload for a class Point using a friend function?
- A. Point Point++(int,Point)
- B. int Point++()
- C. Point operator++(Point, int)
- D. Point operator++(Point)
Answer: C. A friend post-increment overload needs two parameters β the object reference/value and a dummy int to distinguish it from the prefix version.
Q13Inheritance
Private data members of the base class in inheritance are ____.
- A. Inherited, but can only be accessed via public/protected methods of the base class
- B. Inherited and freely accessible in the derived class
- C. Not inherited at all
- D. Inherited but with no way to access them from the derived class
Answer: A. Private base members are technically part of the derived object's memory layout ("inherited") but only accessible through the base class's own public/protected member functions β never directly by name from the derived class.
Q14Inheritance
In diamond-shaped inheritance problems, there is an occurrence of ____.
- A. Multiple Inheritance only
- B. Multilevel Inheritance only
- C. Multiple AND Multilevel inheritance combined (Hybrid)
- D. Hierarchical Inheritance
Answer: C. The diamond problem arises from hybrid inheritance β two classes multilevel-inherit from one common base, then a class multiply-inherits from both, causing the common base to be duplicated.
Q15Inheritance
If class A is friend of class B and class B is friend of class C, which is TRUE?
- A. Class C is friend of class A
- B. Class A is friend of class C
- C. Class A and Class C do not have a friend relationship
- D. Class A, B and C are all mutual friends
Answer: C. Friendship in C++ is not transitive β it must be explicitly declared between each pair of classes.
Topic: Virtual Functions, Polymorphism & Abstract Classes
Q16Polymorphism
Virtual function is used to ____.
- A. deal with ambiguous scenario in sub-ordinate class
- B. deal with non-ambiguous scenario in super class
- C. achieve run-time polymorphism
- D. create an abstract class only
Answer: C. Virtual functions enable dynamic (late) binding, resolved at run time based on the actual object type pointed to β this is run-time polymorphism.
Q17Polymorphism
An abstract class is useful when ____.
- A. no classes should be derived from it
- B. no objects should be instantiated from it (it defines a common interface)
- C. you want to defer only variable declaration
- D. there is only one derived class possible
Answer: B. Abstract classes contain at least one pure virtual function and exist purely to define an interface/contract β they cannot be instantiated; only their concrete derived classes can be.
Q18Polymorphism
The function call being fixed before the program executes is called:
- A. Dynamic linkage
- B. Late binding
- C. Static linkage (early binding)
- D. Run time binding
Answer: C. Static/early binding resolves the function to call at compile time (default for all non-virtual functions).
Q19Polymorphism
Which of the following is an abstract class?
- A. Class having a virtual function (with a body)
- B. Derived class that provides definition of the pure virtual base function
- C. Derived class that does NOT define the pure virtual base class function
- D. None of these
Answer: C. If a derived class fails to override a pure virtual function, it inherits that pure virtual function unimplemented β making the derived class abstract too.
Q20Polymorphism
Which of the following CANNOT be considered polymorphism in OOP?
- A. Function Overloading
- B. Operator Overloading
- C. Constructor Overloading (this is just a form of function overloading β commonly the "odd one out" trick answer)
- D. Function Overriding
Note: This is a conceptually debated MCQ from the paper. In the strictest textbook sense, function overloading, operator overloading, and function overriding are all recognized forms of polymorphism (compile-time or run-time); constructor overloading is technically just function overloading applied to constructors, so exams sometimes flag it as the exception. Read the exact option wording carefully on exam day.
Topic: Operator Overloading
Q21Operator Overloading
Operator overloading using a friend function takes ____ argument(s) than using a member function.
- A. One lesser argument
- B. One more argument
- C. Same number of arguments
- D. Two more arguments with reference
Answer: B. A member function implicitly receives the left operand via this, so it needs one fewer explicit parameter than an equivalent friend function.
Q22Operator Overloading
Which of the following operators CANNOT be overloaded?
- A. Bitwise operator
- B. Relational operator
- C. Conditional (ternary ?:) operator
- D. Arithmetic operators
Answer: C. The operators that cannot be overloaded in C++ are: ::, ., .*, ?:, and sizeof.
Q23Operator Overloading
Which is the CORRECT statement about operator overloading?
- A. Only arithmetic operators can be overloaded
- B. Only non-arithmetic operators can be overloaded
- C. Precedence of operators changes after overloading
- D. Associativity and precedence of operators does NOT change
Answer: D. Overloading changes what an operator does for a user-defined type, but its precedence and associativity (order of evaluation relative to other operators) always remain fixed by the language.
Q24Operator Overloading
For overloading the prefix ++ operator using a friend function, the correct signature is:
- A. Return-type operator++() (member style β no friend keyword needed)
- B. Return-type operator++(int)
- C. friend Return-type operator++(Point&)
- D. friend Return-type operator++(int)
Answer: C. As a friend function, prefix ++ needs exactly one explicit parameter (the object reference) and no dummy int; postfix needs the object reference PLUS a dummy int.
Topic: Templates / Generic Programming
Q25Templates
Template in C++ ____.
- A. is a way of achieving procedural programming
- B. is a way of achieving generic programming
- C. is a way of achieving object-oriented programming specifically
- D. is a way of achieving run-time polymorphism
Answer: B. Templates let functions/classes operate on generic types, determined at compile time based on the arguments/types supplied β this is generic programming.
Q26Templates
Which is the correct syntax for defining a member function of a class template outside the class declaration?
- A. template<A> A className<A>::function_name()
- B. template<class A> ReturnType className<A>::function_name(){ }
- C. template<A> <A> className A::function_name()
- D. template<A> A className::function_name()
Answer: B. The template<class A> header must be repeated immediately before each out-of-class member definition, and the class name must be written with its template parameter as className<A>, followed by :: and the function name.
Topic: Exception Handling
Q27Exceptions
Exceptions in OOP are ____.
- A. Syntax errors
- B. Runtime anomalies
- C. Logical errors
- D. Compile time errors
Answer: B. Exceptions represent unexpected runtime conditions (e.g., division by zero, invalid array index) that disrupt normal program flow β handled using try/catch/throw.
Q28Exceptions
The catch statement to catch a string literal thrown from the try block is:
- A. catch(char s[])
- B. catch(string s)
- C. catch(const char *s)
- D. catch(...)
Answer: C. A string literal thrown with throw "message"; has type const char*, so the catch parameter must match that exact type.
Q29Exceptions
Rethrowing an exception is done using:
- A. A mandatory argument passed to throw
- B. Multiple catch sections only
- C. The bare keyword throw; (no operand) inside a catch block
- D. A nested block of try and catch, mandatorily
Answer: C. Writing just throw; inside a catch block re-throws the exact same exception object currently being handled, passing it to an outer/enclosing handler.
Topic: Friend Functions & Static Members
Q30Friend Function
Friend functions of a class are those functions which can ____.
- A. only be used in overloading
- B. access private, protected AND public data members of the class (full access)
- C. access data members only with public access specifier
- D. access only private data members, nothing else
Answer: B. A friend function has unrestricted access to ALL members of the class it is declared friend of, regardless of their access specifier.
Q31Static Members
How can a static member function show() of class B be accessed from main(), given A is an object of class B?
- A. B::show()
- B. B:show
- C. A::show()
- D. A::show
Answer: A. Static members belong to the class, not any single object, so the conventional and recommended access is via the class name and scope resolution operator: ClassName::staticMember().
Q32Static Members
Default access specifier for data members of a class in C++ is:
- A. Public
- B. Private
- C. Internal
- D. Protected
Answer: B. Members of a class are private by default (whereas members of a struct are public by default).
Topic: References, Overloading vs Overriding, Inline & Misc.
Q33Function Overloading
Function overloading is an example of:
- A. Inheritance
- B. Dynamic (run-time) polymorphism
- C. Static (compile-time) polymorphism
- D. Function overriding
Answer: C. Since the correct overloaded function is selected at compile time based on argument types/count, function overloading is compile-time (static) polymorphism.
Q34References
Which of the following is FALSE about references in C++?
- A. References cannot be NULL
- B. A reference must be initialized when declared
- C. Once created, a reference cannot later be made to reference another object
- D. References cannot refer to a constant value (FALSE β they CAN, via const int& r = 5;)
Answer: D. Statements A, B, and C are all true properties of references. A reference absolutely CAN bind to a constant value using const β so D is the false statement.
Q35References
What are the advantages of passing arguments by reference?
- A. Changes to parameters within the function affect the original arguments
- B. No need to copy parameter values (less memory used)
- C. No need to call constructors for parameters (faster)
- D. All of the mentioned
Answer: D. Pass-by-reference avoids copying (saving memory and constructor-call overhead) and allows the called function to directly modify the caller's original variable.
Q36Inline Function
An inline function executes ____ than a normal function but requires ____ memory.
- A. Slower, low
- B. Slower, high
- C. Faster, low (actually: faster execution, but HIGHER memory)
- D. Faster, high
Correct concept: An inline function executes faster (no call overhead β code is copy-pasted at every call site), but requires more/higher memory since the function body is duplicated everywhere it's called. Watch this option carefully β many past papers phrase the "high memory" trade-off as the distractor. The technically accurate pairing is Faster, high.
Q37Misc / Header Files
In C++, the setw manipulator is declared in which header file?
- A. <iostream>
- B. <fstream>
- C. <cstdio>
- D. <iomanip>
Answer: D. Stream manipulators that take arguments β setw, setprecision, setfill β are declared in <iomanip>.
Q38Misc / Default Args
Which concept of OOP allows the compiler to insert arguments into a function call automatically, when not explicitly specified?
- A. Call by value
- B. Call by reference
- C. Default argument
- D. Call by pointer
Answer: C. Default arguments (e.g., int fun(int x, int y=0)) let the compiler supply a value automatically when the caller omits that argument.
Q39Code Trace
What is the output? int fun(int x,int y=0,int z=5){return x+y+z;} int main(){cout<<fun(5);}
- A. 0
- B. 5
- C. 10
- D. Compiler Error
Answer: C. (10) Only x is supplied (x=5); y defaults to 0 and z defaults to 5. So x+y+z = 5+0+5 = 10.
Q40Code Trace
int a=10,b,c; b=a++; c=a; cout<<a<<" "<<b<<" "<<c; β what is printed?
- A. 10 11 11
- B. 11 10 11
- C. 11 11 11
- D. 10 10 10
Answer: B (11 10 11). a++ is post-increment: b gets the OLD value of a (10), then a becomes 11. c=a then copies the now-updated a (11). Final: a=11, b=10, c=11.
Q41Access Specifiers
A member function can always access the data of ____.
- A. only its own calling object
- B. its class name (static context) only
- C. any object of the class of which it is a member
- D. any public part of any class
Answer: C. A member function can access the private/protected data of any object of its own class β not just the object it was called on (this is why copy constructors can read another object's private members directly).
Q42Destructor
Destructors are those functions which:
- A. Get called when the object is destroyed
- B. Get automatically called when object contents are updated
- C. Get automatically called when the object goes out of scope
- D. Get called when memory space for the object is deallocated (manually)
Answer: C. The precise trigger is scope-exit or explicit delete of a heap object β "object goes out of scope" is the standard textbook phrasing tested in these papers.
Q43Type Casting
Which one is the main purpose of the destructor?
- A. Kill the class
- B. Destruct the object (imprecise wording)
- C. Deallocate and clean up resources occupied by an object
- D. Deallocate and clean up resources occupied by a class (classes themselves don't hold runtime resources)
Answer: C. The destructor's job is resource cleanup (freeing dynamically-allocated memory, closing files/handles, etc.) tied to a specific object's lifetime β not the class definition itself.
Q44new/delete
If new keyword is used in the default constructor to allocate a member, its paired delete keyword should appropriately be used in:
- A. parameterized constructor
- B. copy Constructor
- C. member function of the class
- D. destructor of the class
Answer: D. Every new in a constructor must be matched with a delete in the destructor to avoid memory leaks β this is the RAII (Resource Acquisition Is Initialization) principle.
Q45Inheritance
If class A is inheriting class B as class A: protected B, then:
- A. Public members of B become protected members of A
- B. Public members of A become protected members of B
- C. Protected members of A become private members of B
- D. Public members of B become public members of A
Answer: A. With protected inheritance, both the public and protected members of the base class become protected members in the derived class.
Q46Constructor Types
Given Example(){a=a;b=b;c=c;} //Ctor1, Example(int x,int y,int z){a=x;b=y;c=z;} //Ctor2, Example(Example &E){} //Ctor3 β if we write Example E(1,2,3); Example E1=E; in main(), which constructor(s) are called?
- A. Constructor 1 and Constructor 2
- B. Constructor 2 and Constructor 3
- C. Constructor 2 only
- D. Generate error
Answer: B. Example E(1,2,3) invokes the parameterized constructor (Ctor2). Example E1 = E; is copy-initialization from an existing object, invoking the copy constructor (Ctor3).
Q47Virtual Base Class
Static linkage of a base class pointer with base class members can be avoided by using:
- A. Virtual base class
- B. Abstract class
- C. Virtual function
- D. Derived class pointer
Answer: C. Declaring the function virtual forces dynamic (late) binding through a base class pointer/reference, overriding the default static linkage.
Q48Generic Programming
Template is used to achieve ____ in OOP.
- A. generic Programming
- B. functional Programming
- C. modular Programming
- D. hierarchical programming
Answer: A. Templates parametrize code by type, allowing the same logic to be reused generically across many data types.
Q49Software Reuse
What is a form of software reuse in which the programmer creates a new class from an existing one?
- A. Abstraction
- B. Inheritance
- C. Encapsulation
- D. Polymorphism
Answer: B. Inheritance is the primary code-reuse mechanism in OOP β a derived class reuses (and extends) the members of an existing base class.
Q50Virtual Function
A ____ is a member function that is declared within a base class and redefined by a derived class.
- A. Friend function
- B. Const member function
- C. Virtual function
- D. Static function
Answer: C. This is the textbook definition of a virtual function β declared (optionally with a default body) in the base class, and overridden by derived classes.
Q51Diamond Problem
Diamond Problem in C++ can be solved using ____.
- A. virtual base class
- B. virtual function
- C. inheritance (generically)
- D. polymorphism (generically)
Answer: A. Declaring the shared common ancestor as a virtual base class in both intermediate classes ensures only one copy of it exists in the most-derived object, resolving the ambiguity.
Q52Array Passing
When an array name is passed to a function, the function ____.
- A. accesses exactly the same array as the calling program
- B. accesses a copy of the array passed by the program
- C. refers to the array using the same name as the caller (irrelevant detail)
- D. refers to the array using a different name from the calling program
Answer: A. Array names decay to pointers; passing an array to a function passes the address of its first element, so the function operates on the ORIGINAL array, not a copy.
Q53strlen()
What will be the output? char ch[]="Interviewbit Scaler"; int l=strlen(ch); cout<<l;
Answer: C. "Interviewbit Scaler" has 20 characters (12 letters + 1 space + 7 letters = 20); strlen excludes the null terminator.
Q54Multi-level Inheritance
When there is inheritance where class D: B and class E: D, the order of destructor calls when an E object is destroyed will be:
- A. E(), D() and B()
- B. D(), E() and B()
- C. B(), E() and D()
- D. E(), D() and B() β destructors run in the EXACT REVERSE of construction order
Answer: D. Construction order is B() β D() β E() (base to most-derived). Destruction always runs in the exact reverse: E() β D() β B() (most-derived to base).
Q55Static Function Access
Static function count() of class A can be accessed by ____ from the main() function, where B is an object of class A.
- A. A::count()
- B. B::count
- C. A::count (missing parentheses β not a call)
- D. B::count()
Answer: A. Static members are best accessed via ClassName::member() β using the class name directly, not the object name (though B.count() would also technically work since B is an object of A).