OOP with C++

Encapsulation & Abstraction — Practice MCQs for CCAT

20 Questions Section B: Programming OOP with C++

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

Q1.
Encapsulation means:
AInheritance
BBundling data and methods together
CMultiple classes
DFunction calls
Show Answer & Explanation

Correct Answer: B — Bundling data and methods together

Encapsulation wraps data and methods that operate on data within a class.

Q2.
Data hiding is achieved by:
AMaking members public
BMaking members private
CUsing inheritance
DUsing pointers
Show Answer & Explanation

Correct Answer: B — Making members private

Private members hide data from outside access.

Q3.
Getter and setter methods are used for:
ADirect access
BControlled access to private data
CDeleting data
DCopying objects
Show Answer & Explanation

Correct Answer: B — Controlled access to private data

Getters/setters provide controlled access to private members.

Q4.
Abstraction means:
AShowing implementation
BHiding implementation details
CMultiple inheritance
DOperator overloading
Show Answer & Explanation

Correct Answer: B — Hiding implementation details

Abstraction hides complex implementation and shows only necessary features.

Q5.
Which access specifier provides most restriction?
Apublic
Bprotected
Cprivate
Dfriend
Show Answer & Explanation

Correct Answer: C — private

Private is most restrictive - accessible only within the class.

Q6.
Protected members are accessible in:
AOnly same class
BSame class and derived classes
CEverywhere
DOnly derived class
Show Answer & Explanation

Correct Answer: B — Same class and derived classes

Protected members are accessible in the class and its derived classes.

Q7.
Which is NOT a pillar of OOP?
AEncapsulation
BCompilation
CInheritance
DPolymorphism
Show Answer & Explanation

Correct Answer: B — Compilation

Four pillars of OOP: Encapsulation, Abstraction, Inheritance, Polymorphism.

Q8.
Interface in C++ is achieved using:
Ainterface keyword
BAbstract class with pure virtual functions
CStruct
DUnion
Show Answer & Explanation

Correct Answer: B — Abstract class with pure virtual functions

C++ doesn't have interface keyword; uses abstract classes with pure virtual functions.

Q9.
Benefit of encapsulation:
AFaster execution
BData protection and modularity
CLess memory
DNo benefit
Show Answer & Explanation

Correct Answer: B — Data protection and modularity

Encapsulation protects data and provides modularity.

Q10.
const member function:
ACan modify members
BCannot modify non-static members
CMust be static
DCannot be called
Show Answer & Explanation

Correct Answer: B — Cannot modify non-static members

const member function cannot modify non-static data members.

Q11.
What is data abstraction?
AHiding implementation details
BCopying data
CDeleting data
DSorting data
Show Answer & Explanation

Correct Answer: A — Hiding implementation details

Data abstraction hides implementation details and shows only functionality to users.

Q12.
Pure virtual function is declared using:
Apure keyword
B= 0 syntax
Cabstract keyword
Dvirtual only
Show Answer & Explanation

Correct Answer: B — = 0 syntax

Pure virtual function is declared with = 0: virtual void func() = 0;

Q13.
Abstract class can have:
AOnly pure virtual functions
BBoth pure virtual and regular functions
CNo functions
DOnly static functions
Show Answer & Explanation

Correct Answer: B — Both pure virtual and regular functions

Abstract class can have both pure virtual functions and regular member functions.

Q14.
Getter methods are used to:
AModify private data
BRead private data safely
CDelete data
DCreate objects
Show Answer & Explanation

Correct Answer: B — Read private data safely

Getter (accessor) methods provide controlled read access to private data members.

Q15.
Setter methods are used to:
ARead data
BModify private data with validation
CPrint data
DDelete objects
Show Answer & Explanation

Correct Answer: B — Modify private data with validation

Setter (mutator) methods provide controlled write access with optional validation.

Q16.
Loose coupling means:
AClasses are tightly dependent
BClasses have minimal dependencies
CNo classes
DSingle class design
Show Answer & Explanation

Correct Answer: B — Classes have minimal dependencies

Loose coupling means classes have minimal dependencies on each other, improving maintainability.

Q17.
Information hiding is achieved through:
APublic members
BPrivate members and public interfaces
CGlobal variables
DFriend functions only
Show Answer & Explanation

Correct Answer: B — Private members and public interfaces

Information hiding uses private members accessed through public methods (getters/setters).

Q18.
Which provides better abstraction?
AConcrete class
BAbstract class or interface
CGlobal functions
DStruct
Show Answer & Explanation

Correct Answer: B — Abstract class or interface

Abstract classes and interfaces provide better abstraction by defining contracts without implementation.

Q19.
Advantage of encapsulation:
AFaster execution
BEasier maintenance and data integrity
CLess memory
DMore global access
Show Answer & Explanation

Correct Answer: B — Easier maintenance and data integrity

Encapsulation provides easier maintenance, data integrity, and protection from misuse.

Q20.
Header files in C++ promote:
ATight coupling
BInterface abstraction and separate compilation
CSlower compilation
DData exposure
Show Answer & Explanation

Correct Answer: B — Interface abstraction and separate compilation

Header files separate interface from implementation, promoting abstraction and modularity.