Classes-and-objects questions often hide a small access or lifetime rule inside familiar syntax. You may know the definitions and still reverse the base and derived direction, confuse . with ->, or treat delete as a general-purpose eraser. Solve each item before reading its explanation. Linked headings open either the individual practice item or, when that page is unavailable, the Classes and Objects topic hub. Use Coding & Skills as the broader learning route.
Class members and object-pointer access
class Counter {
private:
int value = 7;
public:
void add(int n) { value += n; }
public:
int read() const { return value; }
static int created;
};
int Counter::created = 1;
int main() {
Counter c;
Counter* p = &c;
p->add(5);
}p->add(5) changes 7 to 12, so c.read() and p->read() return 12; p->read() means (*p).read(). Counter::created is 1, and repeated public: labels are legal.
Question 1: Test friend, static and access-specifier rules (HTET 2022)
In context of C++, which of the following is a valid statement?
A. Friend function of a class is always member function of that class.
B. Value of static data member cannot be changed once assigned.
C. Keywords private, protected and public may appear in any order and any number of times in a class.
D. Static data member of a class can be accessed only by static member function of that class.
Answer: C. Access specifiers may repeat in any order. A friend can access non-public state but is not a member. static is mutable; non-static members and permitted class-qualified code can access it.
Question 2: Choose the operator for a pointer to an object (TPSC Assistant Programmer 2025)
In C++, which operator is used to access members of a class using a pointer ?
A. .
B. ->
C. ::
D. &
Answer: B. ->. Here p->read() equals (*p).read(). Objects use ., scopes use ::, and & takes addresses. C++ Programming focuses on class syntax, MCQs and coding practice.
Dynamic allocation, bounds and object lifetime
For int* ptr = new int[4]{6, 12, 18, 24};, valid indices are 0 to 3, and ptr[3] is 24. ptr + 4 may be formed but not dereferenced; ptr[4] = 0x16 is an out-of-bounds write with undefined behaviour.
ptr++ and ptr += 3 move a pointer but do not write to the array. Never overwrite the only pointer that owns the allocation: keep the result of new[] in owner, use a separate cursor for traversal, and release only the original address with delete[] owner; owner = nullptr;. A single Widget* w = new Widget; must instead be paired with delete w;.
Question 3: Identify the direct out-of-bounds write (ISRO 2025)
Consider following C++ snippet, which allocates memory?int *ptr; ptr = new int [4]; Which of the following statements may make the program crash when executed subsequently?
A. ptr++;
B. ptr += 3;
C. ptr[4] = 0x16;
D. ptr = null;
Answer: C. ptr[4] = 0x16;. Four integers have indices 0 through 3, so index 4 invokes undefined behaviour. A and B can cause later misuse; null as written is not the standard C++ null-pointer literal.
Question 4: State the memory role of delete (TPSC Assistant Programmer 2025)
In C++, what does the delete operator do ?
A. Deletes a member of a class
B. Frees dynamically allocated memory
C. Deletes the class definition
D. Deallocates an object
Answer: B. Frees dynamically allocated memory. delete ends a new object's lifetime, calls its destructor when applicable, and releases storage. D names only the object-level effect, while B gives the full storage-release role of delete. It removes no member or class definition; arrays need delete[].
Virtual inheritance and the direction of inheritance
With Root::id = 7, Left and Right derive from Root; Leaf derives from both. Normal inheritance gives Leaf two Root subobjects, each with id = 7; virtual public Root on both paths gives one shared Root with one id = 7.
In class circle : public point, point is the base and circle is derived. Accessible members flow into circle, never backwards.

Question 5: Identify what virtual inheritance prevents (UPPSC Polytechnic Lecturer 2022)
What is virtual inheritance in C++?
A. C++ technique to enhance multiple inheritance.
B. C++ technique to ensure that a private member of base class can be accessed.
C. To avoid multiple inheritance of classes.
D. To avoid multiple copies of the base class in derived class.
Answer: D. To avoid multiple copies of the base class in derived class. The first diamond has two Root copies; the virtual one shares one. Virtual inheritance neither bans multiple inheritance nor exposes private members.
Question 6: Read a base-to-derived declaration in the right direction (KVS 2017)
Assume the C++ definition : class circle : public point Which of the following is false?
A. ‘Point’ is the base class and ‘circle’ is the derived class.
B. The colon (:) in the header of class definition indicates inheritance.
C. The keyword ‘public’ indicates type of inheritance.
D. All the public and protected members of class ‘circle’ are inherited as public and protected members, respectively, into class ‘point’.
Answer: D. A, B and C are correct; D reverses the flow from point into circle. Repair it with OOP for Teaching CS Exams: Classes and Inheritance.
Public inheritance: what stays visible and where
Base has public pub = 10, protected prot = 20 and private priv = 30. Under public inheritance, Derived reads 10 and 20, not priv. Outside, Derived d; d.pub gives 10; d.prot and d.priv fail. The base subobject contains priv = 30 without granting direct access.
Question 7: Find the false statement about public inheritance (KVS 2018)
Which of the following is not true in case of public inheritance in C++?
A. Each public member in the base class is public in the derived class.
B. Each protected member in the base class is protected in the derived class
C. Each private member in the base class remains private in the base class.
D. Each private member in the base class remains private in the derived class.
Answer: D. Public and protected members retain their categories. Base-private state never becomes directly accessible to Derived.
Question 8: Apply the derived-class accessibility test (DSSSB 2018)
In case of public inheritance in C++, which of the following correctly represents the accessibility of the data variables from derived class?
A. Private variables: Yes, Protected variables: Yes, Public variables: Yes
B. Private variables: Yes, Protected variables: No, Public variables: Yes
C. Private variables: No, Protected variables: Yes, Public variables: Yes
D. Private variables: No, Protected variables: No, Public variables: Yes
Answer: C. A derived member accesses pub = 10 and prot = 20, not priv = 30. The pattern is No, Yes, Yes.
Protected versus private inheritance across two generations
First derives from that Base; Second : public First.
First edge | Effect inside | Access from |
|---|---|---|
public inheritance | public/protected remain public/protected |
|
protected inheritance | public/protected become protected |
|
private inheritance | public/protected become private | neither |
priv = 30 stays inaccessible. A protected first edge passes 10 and 20 to Second; a private edge passes neither.
Question 9: Track protected inheritance into a second derived class (DSSSB 2018)
In case of protected inheritance in C++, which of the following correctly represents the accessibility of the data variables from second derived class?
A. Private variables: Yes, Protected variables: Yes, Public variables: Yes
B. Private variables: Yes, Protected variables: No, Public variables: Yes
C. Private variables: No, Protected variables: Yes, Public variables: Yes
D. Private variables: No, Protected variables: No, Public variables: Yes
Answer: C. Values 10 and 20 become protected in First, so Second uses both. priv = 30 stays inaccessible: No, Yes, Yes.
Question 10: Track private inheritance into a second derived class (DSSSB 2018)
In case of private inheritance in C++, which of the following correctly represents the accessibility of the data variables from second derived class?
A. Private variables: Yes, Protected variables: No, Public variables: Yes
B. Private variables: Yes, Protected variables: No, Public variables: No
C. Private variables: Yes, Protected variables: Yes, Public variables: Yes
D. Private variables: No, Protected variables: No, Public variables: No
Answer: D. Public and protected members become private in First, blocking Second. priv = 30 is inaccessible: No, No, No.
A stream object is still a class object
Assume VIEWS.TXT contains exactly KG. Construct fstream F("VIEWS.TXT", ios::in | ios::out);, read K and G, then run F.clear(); F.seekp(2); F << "AI";. The file becomes KGAI.
F is an object. Its constructor gets a filename and bitmask; ios::in enables input, ios::out output, and | combines them. ? does not.
Question 11: Open one stream for reading and writing (NVS 2022)
Which of the following C++ statements will open a text file "VIEWS.TXT" in which read as well as write activities are required at the same time?
A. fstream F("VIEWS.TXT", ios::read | ios::write);
B. fstream F("VIEWS.TXT", ios::in | ios::out);
C. fstream F("VIEWS.TXT", ios::in ? ios::out);
D. fstream F("VIEWS.TXT", ios::read ? write);
Answer: B. fstream F("VIEWS.TXT", ios::in | ios::out);. ios::in and ios::out are standard; | combines them. A and D use non-standard names; C uses the conditional operator. Revise fundamentals with the C++ Tutorial.
Convert the 11 answers into a revision plan
Map errors first: Questions 1 and 2 test member rules; 3 and 4 dynamic lifetime; 5 and 6 inheritance structure; 7 to 10 access control; and 11 stream-object construction. This error map tells you which example to rerun, not only how many answers you got right.
Award one point per correct first attempt. At 9-11, revise missed rules and retry after two days. At 6-8, rerun the Counter, Root diamond and Base/First/Second examples by hand. At 0-5, rebuild the concept sequence before another mixed set. These are study bands, not exam cutoffs.
For focused C++ concepts and MCQs, use the C++ Programming course already linked. For several languages and coding rounds, use Coding For Placements.




