๐Ÿ“ข Too many exams? Donโ€™t know which one suits you best? Book Your Free Expert ๐Ÿ‘‰ call Now!

  • google app store apple app store
  • โœ–

      Question

      Which of the following best illustrates Encapsulation

      in Object-Oriented Programming?
      A Bundling data and methods together while restricting direct access to some components Correct Answer Incorrect Answer
      B Allowing multiple objects to interact through message passing. Correct Answer Incorrect Answer
      C Hiding complex implementation details from the user Correct Answer Incorrect Answer
      D Enabling a class to inherit properties and methods from another class. Correct Answer Incorrect Answer
      E Defining a one-to-many relationship between objects. Correct Answer Incorrect Answer

      Solution

      Encapsulation is a key OOP principle that involves combining data (fields) and methods (functions) into a single unit (class) and controlling access to them using access modifiers like private, protected, and public. For instance, a BankAccount class might hide its balance field (using private access) and expose methods like deposit() and withdraw() to manipulate it. Encapsulation ensures data integrity and security , preventing unauthorized access or modifications. Why Other Options Are Incorrect : 2. Allowing multiple objects to interact through message passing : This describes Message Passing , which focuses on communication between objects. 3. Hiding complex implementation details from the user : This is Abstraction , not Encapsulation. 4. Enabling a class to inherit properties and methods from another class : This refers to Inheritance , unrelated to Encapsulation. 5. Defining a one-to-many relationship between objects : This aligns with Aggregation or Composition , not Encapsulation.

      Practice Next
      ask-question