In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
In this issue, the editor will bring you about the meaning of public, private, protecte, default and public void in Java. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
The default is default when members of the class do not write access decorations. The default is public for other classes in the same package and private for other classes that are not in the same package. Protected is equivalent to being public to subclasses and private to classes that are not in the same package without parent-child relationships.
Explain the meaning of the access modifiers public, private, protecte, default in Java:
Public (interface access): the most restrictive modifier in the Java language, commonly referred to as "public". The modified classes, properties, and methods can be accessed not only across classes, but also across package.
Private (you cannot access): the narrowest modifier for access restrictions in the Java language, commonly referred to as "private". The modified classes, properties, and methods can only be accessed by the objects of this class, and their subclasses cannot be accessed, let alone cross-package access.
Protected (inherited access): an access modifier between public and private, commonly referred to as a "guard". The modified classes, properties, and methods can only be accessed by the methods and subclasses of the class itself, even if the subclasses are in different packages.
Default (package access): that is, without any access modifiers, commonly referred to as "default access mode". In this mode, access is only allowed in the same package.
What is the meaning of public void in java
The most basic grammar:
Public class HelloWorld {
Public static void main (String [] args) {
System.out.println ("Hello World")
}
}
In java, public is the access modifier of the class, and void is an empty type and no data is returned.
Public void is used for the rest method, indicating that the method can be accessed in the project and there is no return value.
Public is the access modifier of the class, marking your own defined class, which can be accessed in that package, public (public) can be accessed throughout the project private (private) can only be accessed in this class using protected (protected) in subclasses and classes under the same package, and the default access modifier can only be accessed under the same package.
Extended data:
Java is an object-oriented programming language, which not only absorbs the advantages of C++ language, but also abandons the concepts of multi-inheritance and pointers which are difficult to understand in C++, so Java language has two characteristics: powerful and easy to use.
In JAVA, public: means that the members under public: are public members of the class. Other classes or main functions can declare that an object can be accessed directly, while private: is a private member, which can only be accessed inside the class and not accessible outside the class.
The above is the meaning of public, private, protecte, default and public void in Java shared by Xiaobian. If you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.