Practice 20 Classes & Objects multiple-choice questions designed for CDAC CCAT exam preparation. Click "Show Answer" to reveal the correct option with detailed explanation.
Show Answer & Explanation
Correct Answer: B — private
In C++, class members are private by default.
Show Answer & Explanation
Correct Answer: A — public
In C++, struct members are public by default (unlike class).
Show Answer & Explanation
Correct Answer: B — Blueprint for objects
A class is a blueprint/template that defines properties and behaviors for objects.
Show Answer & Explanation
Correct Answer: B — Instance of class
An object is an instance of a class.
Show Answer & Explanation
Correct Answer: B — When object is created
Constructor is automatically called when an object is created.
Show Answer & Explanation
Correct Answer: A — ~ClassName
Destructor name is class name prefixed with tilde (~).
Show Answer & Explanation
Correct Answer: D — Constructor and Destructor
Both constructor and destructor have same name as class (destructor with ~).
Show Answer & Explanation
Correct Answer: B — Reference to same class object
Copy constructor takes a reference to object of same class.
Show Answer & Explanation
Correct Answer: B — All objects of class
Static members are shared by all objects of the class.
Show Answer & Explanation
Correct Answer: B — Private and protected members
Friend function can access private and protected members of the class.
Show Answer & Explanation
Correct Answer: B — private
In C++, class members are private by default, unlike struct members which are public.
Show Answer & Explanation
Correct Answer: B — Object is initialized from another object
Copy constructor is invoked when an object is initialized using another object of the same class.
Show Answer & Explanation
Correct Answer: B — :: scope resolution
Scope resolution (::), member access (.), sizeof, and ternary (?:) operators cannot be overloaded.
Show Answer & Explanation
Correct Answer: B — ~ tilde
Destructor is named with tilde (~) followed by class name, e.g., ~ClassName().
Show Answer & Explanation
Correct Answer: A — Address of current object
this pointer holds the address of the current object invoking the member function.
Show Answer & Explanation
Correct Answer: C — Unlimited
There is no limit on the number of objects that can be created from a class (limited only by memory).
Show Answer & Explanation
Correct Answer: A — Only static members
Static member functions can only access static data members as they have no this pointer.
Show Answer & Explanation
Correct Answer: B — Losing derived class data when assigned to base
Object slicing occurs when a derived class object is assigned to base class, losing derived-specific data.
Show Answer & Explanation
Correct Answer: B — Modification in const member function
Mutable members can be modified even inside const member functions.
Show Answer & Explanation
Correct Answer: B — Inside class definition
Functions defined inside the class body are implicitly inline functions.