Encapsulation in Java

Overview

Encapsulation is done when you declare the properties of a class with private access modifier. As these properties are private you can't access these properties outside a class, even with it objects. So if you want to access these properties, you have to use Getter and Setter methods. This is called encapsulation.

Reference



Comments

Popular posts from this blog

HashMap, TreeMap and LinkedHashMap difference

Language Fundamentals in Java

Collections in Java