-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Learn Java with Projects
By :

One of the cornerstones of OOP is the principle of encapsulation (data abstraction). Encapsulation can be achieved using access modifiers. Before we discuss encapsulation, we must understand the access modifiers themselves.
Access modifiers determine where a class, field, or method is visible and therefore available for use. The level you are annotating at, determines the available access modifiers:
public
or package-private (no keyword)private
, package-private, protected
, and public
Let’s discuss these in turn.
A member marked as private
is accessible within its own class only. In other words, the block scope of the class defines the boundary. When in a class (scope), you cannot access the private
members of another class, even if you have an object reference to...