Encapsulation (Java)

Encapsulation is the practice of hiding an object's internal data and exposing it only through controlled methods. In Java, you do this by making fields…