Sources, coverage and corrections
The three supplied Infeepedia PDFs are preserved unchanged below. The web lessons explain the same topic areas in a new learning order and add foundations for readers who know Python and JavaScript. Source statements and answer keys can contain errors; use the reviewed explanation alongside the original.
- Complete original notes · 45 pages
- Assignment 1 · 20 pages · 99 printed questions
- Assignment 2 · 28 pages · 100 printed questions
All 199 printed questions, including duplicates, retain their wording, choices, source page and number. Assignment 1 has no printed question 99. Its answer-key entry 99 matches printed question 98 (const member-function overloading); this mapping is explicit. No missing question has been invented.
There are 160 scored questions and 39 review-only questions. The latter remain in topic practice but do not enter timed tests, accuracy or wrong-answer lists. These assignments are not represented as official BPSC papers or official answer keys.
Assignment corrections and ambiguous items
Open an entry to compare the supplied key with the review. Every other question also includes its original key after you answer.
Assignment 1, Q3: review only
What determines when a variable comes into existence in memory?
The key selects D, but the wording confuses scope with lifetime. Scope tells where a name is visible; storage duration and initialization govern when its object exists. A data type determines representation, not by itself the moment of creation. Learn the distinction rather than treating all three as interchangeable.
Assignment 1, Q8: review only
How many types of constructors are there in C++?
The key's answer 3 is a beginner classification: default, parameterized and copy. It is not an exhaustive C++ language rule: modern C++ also has move constructors and other useful categories. The question must specify its textbook classification before one numerical answer is defensible.
Assignment 1, Q11: review only
Virtual functions in C++ should be declared as:
Public is often a useful interface design, which explains key A, but a C++ virtual function may legally be public, protected or private. Access and overriding are separate rules. Because 'should' does not state a design requirement, this is discussion rather than a uniquely graded fact.
Assignment 1, Q12: review only
Where should virtual functions be defined?
A virtual operation is introduced in a base class, but its implementation may be in that base, in derived classes, or both. A pure virtual declaration need not have an ordinary base implementation. 'Defined' is not the same as 'first declared', so key B is not a universal answer.
Assignment 1, Q17: review only
How many parameters does a default constructor take?
The simple textbook example has zero parameters, which is key A. The precise C++ rule is that a default constructor can be called with zero arguments. Car(int x = 0) also qualifies although it has one parameter. The question incorrectly treats parameters and required arguments as the same thing.
Assignment 1, Q18: review only
What type of inheritance does single-level inheritance support?
Single-level inheritance describes the shape of a class relationship, not 'runtime inheritance'. A derived class directly inherits from one base in the usual example. Runtime selection concerns virtual function calls, not creation of the inheritance relationship. The supplied key B should not be memorized as a rule.
Assignment 1, Q20: review only
Which of the following functions cannot be inherited from a base class?
The key uses the older textbook rule that constructors and destructors are not inherited like ordinary methods. Since C++11, using Base::Base can inherit constructors, while destructors are not inherited. Without a language-version assumption the alternatives do not express one stable modern answer.
Assignment 1, Q32: key B, reviewed D
Which operator can be overloaded to demonstrate polymorphism?
All three listed operators, ||, << and &&, can be overloaded for suitable user-defined types, so D replaces the supplied key B. Overloaded logical operators do not preserve the built-in short-circuit evaluation guarantee. The fact that << is common for stream output does not make it the only overloadable operator.
Assignment 1, Q33: key A, reviewed D
Which of the following describes the overloading of functions?
Function overloading is both ad-hoc polymorphism and compile-time polymorphism in the usual terminology. A and C therefore overlap, making D appropriate under this assignment's multiple-true convention. It is not the runtime selection associated with virtual functions.
Assignment 1, Q39: review only
Can an object be passed as a function?
The question says 'passed as a function', but the key explains passing an object as an argument. Objects can be passed by value, pointer or reference; callable objects can also define operator(). Because these are different ideas, the printed wording is retained for review without scoring it.
Assignment 1, Q47: review only
Which feature reduces the need for nested classes?
There is no general OOP rule that inheritance reduces the need for nested classes. Nesting and inheritance solve different design problems. The key chooses B, but the question gives no concrete design in which that claim can be tested.
Assignment 1, Q52: key D, reviewed E
Which two features of object-oriented programming are the same?
None of the listed pairs are the same concept, so E corrects the supplied D. Encapsulation controls the unit and access; abstraction exposes only relevant detail; inheritance creates a type relationship; polymorphism allows different implementations behind an interface. Related is not identical.
Assignment 1, Q55: key A, reviewed E
Which among the following cannot be used for the concept of polymorphism?
Static member functions can be overloaded, so they can participate in compile-time polymorphism. Constructor overloading and member-function overloading are also valid examples. E corrects a key that appears to confuse all polymorphism with runtime virtual dispatch.
Assignment 1, Q57: key D, reviewed C
Which member function is assumed to call first when there is a case of using function overloading or abstract class?
Overload resolution chooses the viable function that best matches the arguments under the language rules. It does not automatically choose a global function or a local function first. Ties or no suitable candidate produce an error; an abstract class does not introduce a separate call-priority rule.
Assignment 1, Q60: review only
What is the extra feature in classes which was not in the structures?
The key A is meaningful only when comparing a C++ class with a C struct. In C++, structs can have member functions, constructors and access control too. If both types are C++, no option describes the actual default-access distinction; the language context is missing.
Assignment 1, Q65: review only
Which member of the superclass is never accessible to the subclass?
The ordinary teaching rule is that a derived class cannot directly access a base's private members. However, a base can explicitly grant friendship to that derived class. Since the question says 'never' without excluding friendship, key C is too absolute; distinguish normal inheritance access from granted friendship.
Assignment 1, Q66: key C, reviewed E
What is the size of a class?
C++ class types do have sizeof values, so the key's C is wrong. Object layout includes non-static member subobjects, base subobjects, alignment and possibly implementation overhead; it is not simply the largest member or an unqualified sum. Static members are separate, and even an empty complete class object has nonzero size.
Assignment 1, Q68: review only
Which of the following variable violates the definition of encapsulation?
Unrestricted global mutable state can weaken encapsulation, which is why the key chooses C. But a global variable does not automatically violate every encapsulation rule: internal-linkage implementation state is a counterexample. The question needs a particular access/design context before 'violates' becomes a strict fact.
Assignment 1, Q72: review only
The object cannot be________?
Objects can be passed by value, pointer or reference, and callable class objects can be used in function-like contexts. 'Passed as function' has no precise meaning here and also conflicts with question 39's wording. Preserve the key B as source material, but do not derive a general language rule from it.
Assignment 1, Q74: review only
Which of the following feature may be broken if the user does not use the classes in the code?
C++ does not require every program to use classes or objects of user-defined classes. Encapsulation can also be organized through modules and controlled interfaces outside class syntax. The options conflate a particular class-based design with a universal programming requirement, so the key D is not a reliable scored rule.
Assignment 1, Q77: review only
The combination of abstraction of the data and code is viewed in________.
The source key B intends a class as the unit combining data and code. However, the phrase 'combination of abstraction of the data and code' does not distinguish a class definition from an object or an interface clearly enough. Learn the separate definitions rather than memorizing this vague sentence.
Assignment 1, Q78: review only
The principle of abstraction___________.
Abstraction can support OOP and can help avoid duplication, but neither statement is a unique definition. 'Use abstraction at its minimum' is not a language rule. The source's B is retained for comparison, while the printed question remains unscored.
Assignment 1, Q79: review only
Which among the following concept is correct if a user uses the concept of encapsulation in a code?
The intended benefit is representation independence: private internals may change without changing clients if the public contract remains compatible. 'Without modifying any other code' is not guaranteed, and methods do not change a field's declared type at runtime. Key C needs those missing assumptions.
Assignment 1, Q81: review only
Consider the following program and select the right option from the given options: The above program violates the feature of
Returning a writable pointer to private state lets callers bypass controlled operations, so A describes the design risk and B can also be true. The program itself is syntactically valid; merely taking the uninitialized member's address is not reading its value. Because more than one substantive option is defensible and no combined option is supplied, this item is not scored.
Assignment 1, Q88: review only
How can we make a C++ class such that objects of it can only be created using the new operator?
A private destructor can prevent ordinary outside automatic destruction, and a factory/friend can control creation and deletion. A private constructor alone restricts who constructs, not whether that trusted code uses stack or dynamic storage. The key's blanket 'B and C' rule is not sufficient to enforce heap-only allocation in every context.
Assignment 1, Q91: review only
A member function can always access the data in __________.
A member function generally has access privileges for its class, so A captures the intended rule. C is also included in that access, while B's wording treats functions as per-object entities. 'Always' also overlooks the object needed to use a non-static field. The alternatives do not support one exclusive answer.
Assignment 1, Q93: review only
In C++, polymorphism requires:
This question fails to say runtime polymorphism. Compile-time polymorphism through overloading needs neither inheritance nor virtual functions. Even for runtime dispatch, a pointer can be used instead of a reference. The key D should not be learned as an unconditional requirement for all C++ polymorphism.
Assignment 1, Q94: review only
Method overriding can be prevented by using final as a modifier at ______.
In Java, final appears before the method's return type; in C++, it appears after the member-function declarator, as void f() final. The surrounding questions are C++, but the supplied key B describes Java-style placement. Because the language is not specified, this item is retained without scoring.
Assignment 1, Q96: review only
Which of the following overloaded functions are NOT allowed in C++? 1. Function declarations that differ only in the return type. int fun(int x, int y); void fun(int x, int y); 2. Functions that differ only by the static keyword in the return type. int fun(int x, int y); static int fun(int x, int y); 3. Parameter declarations that differ only in a pointer * versus an array []. int fun(int *ptr, int n); int fun(int ptr[], int n); 4. Two parameter declarations that differ only in their default arguments. int fun(int x, int y); int fun(int x, int y = 10);
None of the four changes creates a distinct overload signature in the illustrated forms. Return type alone cannot overload; array parameters adjust to pointers; adding a default argument is a redeclaration, not a new overload. Mixing static and non-static-linkage declarations also needs context. The key D even says 'all except 2 and 4', text that does not match printed option D, so this item is deliberately unscored.
Assignment 1, Q98: key B, reviewed B
Predict the output of the following C++ program:
t1 is non-const, so overload resolution selects fun(); t2 is const, so it selects fun() const. The output is fun() followed by fun() const, with the printed line breaks. The source answer is mislabeled 99 rather than 98; no separate question 99 is printed.
Assignment 1, Q100: review only
Which of the following is NOT correct for virtual functions in C++?
A and B are both incorrect: virtual functions can be non-public and cannot be static. The paper supplies no combined 'more than one' choice here, so key B alone is not unique. Calling through a reference also works, and a pure virtual declaration need not have an ordinary base definition.
Assignment 2, Q7: review only
When a method in a subclass has the same name and type signatures as a method in the superclass, the method in the subclass _____ the method in the superclass.
The intended key is overrides, which describes an eligible Java instance method or a C++ override of a virtual base member. In C++, a same-name, same-signature non-virtual member can instead hide the base member. Because the language and virtual requirement are omitted, this item is discussion-only.
Assignment 2, Q14: key D, reviewed C
In C++, a pure virtual function is:
The defining syntax is a virtual member declaration with = 0. A pure virtual member may still have an out-of-class definition, so A is not a universal rule. A derived class may remain abstract instead of overriding it, so B's unconditional 'must' is also false. C corrects the supplied D.
Assignment 2, Q16: key E, reviewed C
Which of the following is true?
A static member function has no implicit this, but it may access a non-static field through an explicit object, such as obj.x when access is permitted. Static methods can be overloaded, and ordinary instance methods may access static fields. Therefore C corrects the key E; 'cannot access directly without an object' is the rule to remember.
Assignment 2, Q19: key C, reviewed E
What is the output of the following C++ program?
Both pointer arguments refer to number. In the two-argument overload, one multiplication operand reads number while the other modifies it through --(*y), with no sequencing between those operands. That is undefined behavior in C++17, not a guaranteed 870. E corrects the key C; executing it and observing 870 would not establish a valid portable answer.
Assignment 2, Q22: review only
It is possible to define a class within another class, which is called a nested class. How many types of nested classes exist in C++?
C++ supports nested classes, but the language does not define a universal count of 'two types of nested classes'. Static versus non-static nested/inner categories are commonly taught for Java, not as this C++ taxonomy. The key A is retained as a source claim, not a graded language fact.
Assignment 2, Q23: review only
When one object reference variable is assigned to another object reference variable, what happens?
In Java, assigning an object-reference variable copies the reference, so both variables can denote the same object. Python name assignment similarly aliases the object. But assigning through C++ references usually assigns the referred-to object's value rather than reseating a reference. The omitted language makes source key B conditional.
Assignment 2, Q33: review only
In C++, the const qualifier can be applied to which of the following? 1. Member functions of a class 2. Function arguments 3. Class data members declared as static 4. Reference variables
Const-qualified non-static members, const parameters, and static const data members are all possible. A reference itself cannot be cv-qualified like a separate object, but a reference can refer to const data. The numbered combination choices and option D do not clearly encode these distinctions, so the supplied D is not scored.
Assignment 2, Q38: review only
Which of the following is true about pure virtual functions in C++? 1. Their implementation is not provided in the class where they are declared. 2. If a class has a pure virtual function, then the class becomes an abstract class, and an instance of this class cannot be created.
Statement 2 is the intended abstract-class rule, while statement 1 overlooks a pure virtual function's permitted out-of-class definition. A pure declaration cannot include an inline body in that same declaration, but that is not the same as having no implementation at all. The vague wording and D's unusual '(B and C)' combination make this a review item rather than a reliable scored question.
Assignment 2, Q46: key C, reviewed D
What should be put in a try block in C++? 1. Statements that might cause exceptions 2. Statements that should be skipped in case of an exception
A try block encloses operations that may throw and the dependent work that should stop if a throw occurs before it. An exception transfers control to a matching handler and skips remaining statements on that failed path. Thus 1 and 2 support D, correcting the source key C ('None').
Assignment 2, Q52: key B, reviewed E
What will be the output of the following code?
The first literal contains 13 letters plus the terminating null, so sizeof is 14. The second literal visibly has a trailing space, making strlen 14 as well because strlen counts that space but not the null. The actual pair is 14 14, which is absent; E corrects the key B, which overlooks the space.
Assignment 2, Q57: key C, reviewed B
What will be the output of the following code?
Inside the parentheses, the comma operator evaluates its expressions and yields the final value, 3. The outer expression then computes 1 + 3 = 4. B corrects source key C, which forgets the addition outside the parentheses.
Assignment 2, Q60: key B, reviewed E
What will be the output of the following code?
As standard C++17, this is ill-formed: int main(int x) is not a permitted main signature for this implementation, and a program must not call main recursively. No offered output is the standard answer, so E corrects B. If the same body were placed in an ordinary recursive function, its static i would explain the textbook's intended 4321 trace.
Assignment 2, Q61: key C, reviewed E
What will be the output of the following code?
The printed C++ program has the same invalid main signature and forbidden recursive use of main as question 60. Therefore its correct classification is a rejected standard program, not a valid infinite-loop output. In an ordinary function, a fresh automatic i = 5 per call would instead cause unbounded recursion, usually ending in resource exhaustion.
Assignment 2, Q62: key C, reviewed E
What will be the output of the following code?
The two operands of + modify the same x without sequencing between those modifications. C++17 does not assign this expression a portable result: it has undefined behavior. 'Compiler Dependent' is not the same as implementation-defined behavior with a documented choice, so E replaces the source's misleading C.
Assignment 2, Q66: review only
Which of the following statements is correct?
A base pointer can point to an accessible derived object. An actual standalone Base object cannot safely be treated as a Derived, but casts and the distinction between an object and its base subobject make B's 'cannot point' too imprecise. The supplied E and the common intended B rely on different interpretations, so this wording is not scored.
Assignment 2, Q69: review only
Which of the following cannot be used with the keyword virtual?
A constructor cannot be virtual. But 'virtual class' is not a C++ class-declaration keyword combination either; virtual base classes instead use virtual in a base-specifier. The source key C assumes 'class' means a virtual base class, so this imprecise wording is retained without grading.
Assignment 2, Q71: review only
Which of the following problems causes an exception?
Missing semicolons and syntax errors are normally translation errors, not catchable runtime exceptions. 'A problem in the calling function' is too vague: not every problem throws, and errors may also originate in called functions. The key B does not identify a specific exception-producing operation.
Assignment 2, Q72: review only
The compiler checks the type of reference in the object and not the type of object. This concept refers to:
Compile-time checking uses the declared reference type to decide which members are callable. A virtual dispatch can then use the actual object's type to choose an implementation. These are two stages, not one named concept captured uniquely by 'polymorphism', so the source key B is discussed rather than scored.
Assignment 2, Q81: review only
Which of the following are available only in the class hierarchy chain?
Protected members are ordinarily accessible within the declaring class and suitable derived-class contexts. In C++, friends may also access them; in Java, same-package access also matters. Thus 'only in the class hierarchy chain' is not a universal cross-language statement, despite key C.
Assignment 2, Q82: review only
In which of the following cases is a virtual call resolved at the time of compilation?
A virtual call on the object under construction/destruction dispatches within the currently active construction/destruction class, not to a not-yet-constructed or already-destroyed derived part. That is not a blanket language rule that every such call is resolved at compilation. Optimizers can also devirtualize known calls elsewhere, so the source D oversimplifies the issue.
Assignment 2, Q83: review only
Which of the following statements regarding inline functions is correct?
Inlining may reduce call overhead and may increase code size, but either performance result depends on optimization and context. The inline keyword does not require inline expansion at all. Because A and C are written as unconditional claims, the source's D is a heuristic, not a uniquely true language guarantee.
Assignment 2, Q87: key D, reviewed E
What will happen if a class is not having any name?
An unnamed C++ class type is allowed, and objects of it still have implicitly declared special members as applicable. What cannot be written normally is a user-declared constructor/destructor name for that unnamed class. 'Cannot have a destructor/constructor' is therefore too strong, making E the literal correction to key D.
Assignment 2, Q89: key C, reviewed E
Which one of the following is correct about the statements given below? 1. All function calls are resolved at compile-time in Procedure Oriented Programming. 2. All function calls are resolved at compile-time in OOPS.
Neither 'all' claim is generally true. Procedural C can choose a target at runtime through a function pointer, and OOP languages can use virtual runtime dispatch. Thus E corrects the source's C; procedural versus object-oriented does not by itself fix every call's binding time.
Assignment 2, Q94: review only
What is correct about the static data member of a class?
B is the reliable shared-storage rule. A needs the missing phrase 'directly without an object', because a static method may use an explicit instance; C depends on access and qualification such as public Class::field. The key's D combines assumptions the stem never states, so this version is unscored.
Assignment 2, Q95: review only
When does the "diamond problem" occur in programming?
A diamond requires two inheritance paths back to a common ancestor: A -> B/C -> D. Two unrelated parents merely having the same method name can cause ambiguity without forming a diamond. Option B omits the shared ancestor, so the source question does not supply a precise correct definition.
Assignment 2, Q96: review only
A programmer defines a class but fails to create an instance of that class. They try to call a method of the class directly. What type of error will occur?
A static method can be called through its class without an instance. An ordinary non-static Java/C++ method needs an object context, but the stem never says which kind of method or which call syntax is used. Therefore the key's compilation-error answer is conditional, not universally correct.
Assignment 2, Q100: key E, reviewed A
What is the result of compiling and running the following code in Java?
The printed Java uses private: with a colon, which is C++ access-section syntax and is illegal Java. Java requires private int count = 0;. Consequently compilation fails before the separate missing-main issue matters. A corrects the source key E; it is not simply a valid class that produces no output.
Language references
The teaching baseline is C17, C++17 and Java 17, with Python 3 comparisons. The 51 complete worked examples have automated output or expected-compilation-error checks. Syntax fragments and intentionally undefined assignment expressions are not claimed to produce a portable output.