113k views
5 votes
Data hiding (which means that critical data stored inside the object is protected from code outside the object) is accomplished in Java by .

a) Private access modifier
b) Public access modifier
c) Static keyword
d) Final keyword

1 Answer

2 votes

Final answer:

Data hiding in Java is achieved through the use of the private access modifier, which restricts access to class members from outside code, thus protecting sensitive data.

Step-by-step explanation:

In Java, data hiding which is a concept that means critical data stored inside the object is protected from access by code outside the object, is generally accomplished by using a private access modifier. When a member of a class, such as a field or method, is declared as private, it cannot be accessed by code outside of that class. This encapsulation is a fundamental principle in object-oriented programming, enhancing security and integrity by allowing controlled access to sensitive data.

Access modifiers like public, static, and final serve different purposes. The public access modifier allows members to be accessed from outside the class, the static keyword denotes that a member belongs to the class itself rather than an instance of the class, and the final keyword indicates that the value of a variable cannot be changed or that a method cannot be overridden.

User Akayh
by
8.3k points