Skip to content

robhaj/java-encapsulation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

Encapsulation in Java

  • The ability of an object to be a container for its member properties, including variables and methods.
  • A fundamental principle of OOP, encapsulation plays a major role in languages such as C++ and Java.
  • Hides variables from the rest of the program
  • Use getter/setter methods that are public to access them
  • Variables marked as private can only be seen/modified through the use of public accessor (getter) and mutator (setter) methods

Advantages

  • Helps you to control who accesses what
    • Which function has access to a certain variable
  • Makes a code flexible and easy to change
  • Testing is more manageable (unit)

Notes

  • An object's behavior is exposed through methods
  • Hiding internal data from the outside world
  • Accessing it only through publicly exposed methods

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages