which of the following is a benefit of encapsulation? group of answer choices it allows a function defined in one class to be reused in another class. it guarantees that an object cannot be accidentally put into an inconsistent state. it improves the performance of an application. it prevents functions that are internal to a class from changing private data members.

Respuesta :

Answer:

Encapsulation is a programming concept that refers to the bundling of data and the methods that operate on that data within a single unit, or object.

One benefit of encapsulation is that it guarantees that an object cannot be accidentally put into an inconsistent state, which is the correct answer choice.

Explanation:

A) It allows a function defined in one class to be reused in another class. This is not a benefit of encapsulation, but rather a benefit of inheritance, which allows a derived class to reuse the member functions and data of a base class.

B) It guarantees that an object cannot be accidentally put into an inconsistent state. This is a benefit of encapsulation, as it ensures that the data within an object is always valid and consistent by hiding the implementation details of the object and exposing a well-defined interface to the outside world.

C) It improves the performance of an application. This is not a benefit of encapsulation, as encapsulation is concerned with the organization and structure of the code, rather than its performance.

D) It prevents functions that are internal to a class from changing private data members. This is also a benefit of encapsulation, as it allows the data within an object to be protected from external interference or manipulation, and ensures that the object's internal state is maintained consistently.

ACCESS MORE