Information Hiding

Unit 2 Β· Topic 2.2⏱ 8 min read❓ 5 MCQs

Introduction

Information hiding restricts access to an object's internal details, exposing only what is necessary through a public interface.

Definition

Information Hiding: Concealing implementation details; exposing only the interface.

C++ Code Example

#include 
using namespace std;
class BankAccount {
    double balance; // hidden
public:
    void deposit(double a){ balance+=a; }
    double getBalance(){ return balance; }
};

Important Questions

Short Questions

  1. What is information hiding?
  2. Difference hiding vs encapsulation?
  3. Why hide data?
  4. What is public interface?

Long Questions

  1. Explain information hiding with example.
  2. Discuss benefits of information hiding.

MCQ Practice

1. Information hiding is achieved by:

  • Access specifiers
  • Inheritance
  • Templates
  • Virtual functions
Answer: Access specifiers.

2. Hidden members are usually:

  • private
  • public
  • protected
  • static
Answer: private.

3. Public interface provides:

  • Controlled access
  • Direct data access
  • Nothing
  • Compilation
Answer: Controlled access.

4. Information hiding improves:

  • Security
  • Speed
  • Memory
  • None
Answer: Security.

5. Encapsulation is the mechanism for:

  • Information hiding
  • Inheritance
  • Polymorphism
  • Templates
Answer: Information hiding.

Quick Revision

  • Hide data; expose interface.
  • Improves security and maintainability.