Java 11 Cookbook
上QQ阅读APP看书,第一时间看更新

Getting ready

The term object usually refers to an entity that couples data and procedures that can be applied to this data. Neither data nor procedures are required, but one of them isand, typically, both arealways present. The data is called object fields (or properties), while procedures are called methods. Field values describe the object's state. Methods describe the object's behavior. Every object has a type, which is defined by its classthe template used for the object's creation. An object is also said to be an instance of a class.

A class is a collection of definitions of fields and methods that will be present in each of its instances the objects created based on this class.
Encapsulation is the hiding of those fields and methods that should not be accessible by other objects.

Encapsulation is achieved by using the publicprotected, or private Java keywords, called access modifiers, in the declaration of the fields and methods. There is also a default level of encapsulation when no access modifier is specified.