Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Access level of members of Java class

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report