Private as a permission modifier can modify classes, properties and methods; classes, properties and methods modified with private can only be used by yourself and cannot be accessed by other classes, that is to say, for other classes It is hidden and invisible. Private generally does not modify classes, but it can modify internal classes.

You can use private to implement encapsulation:
Encapsulate properties and methods with private to represent the encapsulated properties and methods can only be used within this class and are not visible outside the class.
If you want to access the encapsulated properties at this time, you must provide getter and setter methods
setter method: mainly for setting and modifying the attribute content
getter method: mainly for setting and modifying the attribute content Obtaining attribute content
Design principles for classes: When writing a class, there is no additional explanation. All attributes must be encapsulated privately (member variables)
private cannot be used for external classes Encapsulation, but can be used for encapsulation of inner classes:
class Persion{
//被private封装的属性
private String name;
private int age;
public void setname(String n){
name = n;
}
public String getname(){
return name;
}
public void setage(int num){
if(num>0 && num<p>private is only the first step in encapsulation. </p><blockquote><p>Related learning recommendations: <a href="//m.sbmmt.com/java/base/" target="_blank">java basic tutorial</a></p></blockquote>The above is the detailed content of What does private mean in java. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

Atom editor mac version download
The most popular open source editor

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Mac version
God-level code editing software (SublimeText3)





