Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to understand the access modifier of Java

Shulou Source: shulou.com Published: 2022-06-01 22:37:35 09月29日 Update

This article introduces you how to understand the Java visit modifier, the content is very detailed, interested friends can refer to, hope to be helpful to you.

Java access modifiers, such as public, private, protect, default, etc.

The scope can look directly at the above and say nothing more, let's just talk about the use scenario. There is a saying that I know the truth, but I can't use it. There are also many friends in the group who say they don't know how to use it, so we will also bring the use scene in the future. Of course, the knowledge of knife is also limited. I will share what I know, and we can share it together.

Private:

Generally used in static member constants such as

Public static final String MINI= "programmer Learning Camp"

Private:

From the encapsulation point of view, the suggested variables are defined as private, and then need to be accessed by the outside world, exposing a get method

Private String mini = "programmer learning base"; public String geMini () {return mini;}

Protect:

Commonly used in architecture design to store variables common to subclasses

Public class BaseXXX {protected String mini;} public class SubXXX extends BaseXXX {public String getMini () {return mini;}} access modifiers on how to understand Java are shared here. I hope the above can be of some help and learn more. If you think the article is good, you can share it for more people to see.

Tags: Content variables scenes big books base camp boys buddies more programs programmers learning help good function interest outside world subcategory knowledge knife that is Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn NVidia Apple Shulou Information Microsoft