The part of the code that you publish is an example of both. Encapsulation is a method for which the Java class has state (information stored in the object) and behavior (operations that the object can perform, or rather methods). When you call a method defined in class A in class B, you use this method without knowing its implementation, just using the open interface.
Information Hiding the principle for which istance variables are declared private (or protected): it provides a stable interface and protects the program from errors (as a modification of a variable from a part of the code that should not have access to the aforementioned variable).
Basically:
Encapsulation using information hiding:
public class Person { private String name; private int age; public Person() {
Encapsulation without hiding information:
public class Person { public String name; public int age; public Person() {
In OOP, it is good practice to use both encapsulation and information hiding.
source share