1.

Define encapsulation in context to OOPS.

Answer»

The concept of encapsulation (or OOP Encapsulation) in object-oriented computer programming (OOP) languages REFERS to the bundling of data and the functions that OPERATE on that data into a single unit. Encapsulation is commonly used in the form of classes in several programming languages. A class is a type of program-code template that allows programmers to design objects with both variables (data) and behaviours (functions or methods). In computer science, a class is an example of encapsulation since it consists of data and procedures that have been bundled into a single unit.

Encapsulation can also refer to a mechanism that prevents users from directly accessing specific components of an object, such as state values for all of the object's variables. Data members as well as data functions or methods linked with an instantiated class or object can be hidden via encapsulation.

There are a few fundamental advantages of encapsulation in programming. These are some of them:

  • Data hiding: Users will have no notion how classes are BUILT or stored because data will be hidden. Users will only be aware of the fact that values are being given and initialised.
  • Easy to Adjust and Adapt to New Requirements: Encapsulation makes it simple to CHANGE and adapt to new requirements.
  • More flexibility: You can choose whether to make variables red or write-only. SetName(), setAge(), and setWriteOnly() are some examples. To make variables write-only, simply omit the get methods like getName(), getAge(), and so on.


Discussion

No Comment Found