Skip to content

Latest commit

 

History

History

Encapsulation

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

java-resource

Refresher and resource for OOP concepts, collections, generics, conventions and more.

Encapsulation

Encapsulation in Java is a mechanism of wrapping the variables and methods together as a single unit. In encapsulation, the variables of a class will be hidden from other classes, and can be accessed only through the methods of their current class.

To achieve encapsulation in Java:

  • Declare the variables of a class as private.
  • Provide public setter and getter methods to modify and view the variables values.