Answer:
Option (D) using the private access specifier on the class fields
Step-by-step explanation:
- The private access modifier can be used to hide the data.
- Methods and data variables ( fields ) can be declared with the private access modifier.
- Data hiding is a OOPS Concept which can be achieved with the private keyword (private access modifier).
- The access modifiers are of types Public, Private, Protected and Default ( no access modifier - no need to explicitly specify the default keyword).
- Data hiding means to hide the data, the data is contained in the class variables.So, option (d) using private access modifier on the class fields is correct option.
- Option (A) is wrong as the using the public access modifier doesn't hide anything. It is public and is visible to the public.
- Option (B) is wrong as using the private access modifier on the methods means it is hiding the implementation of the methods not the data.
- Option (C) is wrong as using private access modifiers on class definition means making the classes not visible to other classes it doesn't mean data hiding as the data is contained in the class variables.