𝗝𝗮𝘃𝗮 𝗘𝗻𝗰𝗮𝗽𝘀𝘂𝗹𝗮𝘁𝗶𝗼𝗻 𝗚𝘂𝗶𝗱𝗲

You need to protect your data in Java. This is encapsulation.

Access modifiers control who sees your code.

Use getters and setters to manage this.

Example: A gold shop. The gold price is private. A customer uses a getter to see the price. A customer uses a setter to change the price.

You set rules in the setter. You stop people from setting a price too low.

Encapsulation keeps your data safe. It gives you control.

Source: https://dev.to/buddingdeveloper/understanding-encapsulation-in-javaaccess-modifiers-getters-and-setters-for-beginners-1841