Bird
0
0

What is the main purpose of encapsulation in C#?

easy🧠 Conceptual Q11 of 15
C Sharp (C#) - Properties and Encapsulation
What is the main purpose of encapsulation in C#?
ATo allow direct modification of class fields from anywhere
BTo hide the internal data of a class and protect it from outside access
CTo make all class data public for easy access
DTo increase the size of the program
Step-by-Step Solution
Solution:
  1. Step 1: Understand encapsulation concept

    Encapsulation means hiding data inside a class to protect it from outside interference.
  2. Step 2: Identify the purpose of encapsulation

    It prevents direct access to data, allowing control through methods or properties.
  3. Final Answer:

    To hide the internal data of a class and protect it from outside access -> Option B
  4. Quick Check:

    Encapsulation = Data protection [OK]
Quick Trick: Encapsulation means hiding data inside classes [OK]
Common Mistakes:
MISTAKES
  • Thinking encapsulation makes all data public
  • Confusing encapsulation with inheritance
  • Believing encapsulation increases program size

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Sharp (C#) Quizzes