Encapsulation is the process and data is surrounded, access to data only through the interface defined. Object-oriented computing begins with this basic concept that the real world can be portrayed as a series of fully autonomous, encapsulated objects that access other objects through a protected interface. Encapsulation is an information hiding technology that is encapsulated in Java through the keyword private. What is encapsulation? Encapsulation combines all the components of an object, encapsulates the data that defines how the program references the object, encapsulates the fact that it hides the data of the class, and controls how much the user modifies the class and accesses the data.
Encapsulation is to hide internal implementations and expose access interfaces.
Access modifier: Used to control access rights to resources (default,public,private,protected);
Default: Package access, resources that are decorated with it can only be accessed in the same package.
Public: Publicly accessible, resources that are decorated with it can be accessed at any location.
Private: A resource that is decorated with it can be accessed only in that class.
Protected: Protected Access, which can be accessed by all classes in the same package, or by a quilt class, regardless of which package the subclass is in.
The access modifiers of the class can use only default and public. The access modifier for a property can use either.
Access with Get and set accessors: All class properties are private, allowing eclipse's functionality to implement get and set accessors. In set, the control value is taken. All other places use accessors to read or set. The settings are all in set, and the values are all taken in the get.
- For Exampl
public class Book {
Private String BookName;
Public String Getbookname () {
return bookname;
}
public void Setbookname (String bookname) {
This.bookname = BookName;
}
}
- This enables a package effect.
Java from small white to getting started, Day6. javaoo-Package