OOP with C++

Classes & Objects — Practice MCQs for CCAT

20 Questions Section B: Programming OOP with C++

Practice 20 Classes & Objects multiple-choice questions designed for CDAC CCAT exam preparation. Click "Show Answer" to reveal the correct option with detailed explanation.

Q1.
What is the default access specifier for class members in C++?
Apublic
Bprivate
Cprotected
Dfriend
Show Answer & Explanation

Correct Answer: B — private

In C++, class members are private by default.

Q2.
What is the default access specifier for struct members in C++?
Apublic
Bprivate
Cprotected
DNone
Show Answer & Explanation

Correct Answer: A — public

In C++, struct members are public by default (unlike class).

Q3.
A class is a:
AVariable
BBlueprint for objects
CFunction
DData type only
Show Answer & Explanation

Correct Answer: B — Blueprint for objects

A class is a blueprint/template that defines properties and behaviors for objects.

Q4.
Object is also called:
AClass
BInstance of class
CFunction
DMethod
Show Answer & Explanation

Correct Answer: B — Instance of class

An object is an instance of a class.

Q5.
Constructor is called:
AWhen object is destroyed
BWhen object is created
CManually by user
DNever automatically
Show Answer & Explanation

Correct Answer: B — When object is created

Constructor is automatically called when an object is created.

Q6.
Destructor name is:
A~ClassName
BClassName~
Cdelete ClassName
D-ClassName
Show Answer & Explanation

Correct Answer: A — ~ClassName

Destructor name is class name prefixed with tilde (~).

Q7.
Which can have same name as class?
AAny function
BConstructor only
CDestructor only
DConstructor and Destructor
Show Answer & Explanation

Correct Answer: D — Constructor and Destructor

Both constructor and destructor have same name as class (destructor with ~).

Q8.
Copy constructor takes:
ANo argument
BReference to same class object
CPointer
DInteger
Show Answer & Explanation

Correct Answer: B — Reference to same class object

Copy constructor takes a reference to object of same class.

Q9.
Static member variable is shared by:
AOne object
BAll objects of class
CNo object
DDerived class only
Show Answer & Explanation

Correct Answer: B — All objects of class

Static members are shared by all objects of the class.

Q10.
Friend function can access:
AOnly public members
BPrivate and protected members
COnly protected
DNothing
Show Answer & Explanation

Correct Answer: B — Private and protected members

Friend function can access private and protected members of the class.

Q11.
What is the default access specifier for class members in C++?
Apublic
Bprivate
Cprotected
Dinternal
Show Answer & Explanation

Correct Answer: B — private

In C++, class members are private by default, unlike struct members which are public.

Q12.
Copy constructor is called when:
AObject is assigned
BObject is initialized from another object
CObject is destroyed
DObject is created with new
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.

Q13.
Which operator cannot be overloaded?
A+ operator
B:: scope resolution
C= assignment
D[] subscript
Show Answer & Explanation

Correct Answer: B — :: scope resolution

Scope resolution (::), member access (.), sizeof, and ternary (?:) operators cannot be overloaded.

Q14.
Destructor name is prefixed with:
A@ symbol
B~ tilde
C# hash
D$ dollar
Show Answer & Explanation

Correct Answer: B — ~ tilde

Destructor is named with tilde (~) followed by class name, e.g., ~ClassName().

Q15.
this pointer contains:
AAddress of current object
BAddress of base class
CNULL always
DAddress of main function
Show Answer & Explanation

Correct Answer: A — Address of current object

this pointer holds the address of the current object invoking the member function.

Q16.
How many objects can be created from a class?
AOnly one
BOnly two
CUnlimited
DDepends on compiler
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).

Q17.
Static member functions can access:
AOnly static members
BOnly non-static members
CBoth static and non-static
DNo members
Show Answer & Explanation

Correct Answer: A — Only static members

Static member functions can only access static data members as they have no this pointer.

Q18.
What is object slicing?
ADividing object memory
BLosing derived class data when assigned to base
CSplitting object into parts
DMemory optimization
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.

Q19.
Mutable keyword allows:
AMaking variable constant
BModification in const member function
CCreating global variable
DThread safety
Show Answer & Explanation

Correct Answer: B — Modification in const member function

Mutable members can be modified even inside const member functions.

Q20.
Inline member functions are defined:
AOutside class only
BInside class definition
CIn header file only
DUsing extern keyword
Show Answer & Explanation

Correct Answer: B — Inside class definition

Functions defined inside the class body are implicitly inline functions.