Get the App
SLTechnology News&Howtos  ›  Development  › 

Access level of members of Java class

Shulou Source: shulou.com Published: 2022-06-03 19:16:07 10月04日 Update

This article introduces the relevant knowledge of "access level of Java class members". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The class can be public or default (or package level). In this tutorial, we mainly introduce the use of public,private,protected access-level figures of speech.

The access level of a class member determines which area of the program can access it. One of the following four access level modifiers can be used for class members:

Open (public)

Private (private)

Protection (protected)

Default or package-level access

The first three types of access levels are specified using one of the following three keywords: public,private or protected. The fourth type is called the default access level (or package level) and is specified by not using access modifiers.

If a class member is declared public using the public keyword, it can be accessed from anywhere in the Java code if the class itself is accessible.

If you use the private keyword to declare a class member private, it can only be accessed in the body of the declared class, but not anywhere else.

If you use the protected keyword to declare a class member as protected, you can access such members from a class in the same package or from a subclass of that class, even if the subclass is in a different package.

If you do not use any access-level rhetoric for class members, it has package-level access. Class members with package-level access can be accessed from the same package.

The access level of class members can range from the strictest to the least stringent, that is, private,package-level,protected and public.

This is the end of the content of "access level of Java Class members". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Level member keyword keyword rhetoric content subclass more permission knowledge type protection private different practical successful and then one three subject Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi macOS Apple Docker Huawei