In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "what are the modifiers in Java". Interested friends may wish to have a look at them. The method introduced in this paper is simple, fast and practical. Let the editor take you to learn "what are the modifiers in Java"?
The Java language defines public, protected, private, abstract, static and final, which are six common modifiers and five less commonly used modifiers. Here is an introduction to these 11 Java modifiers:
1.public
Working with objects: classes, interfaces, members
Description: no matter where the package definition is, this class (interface, member) is accessible
2.private
Working with objects: member
Introduction: a member can only be accessed in the class that defines it
3.static
Use objects: classes, methods, fields, initialization functions
Introduction: the inner class named static is a top-level class that has nothing to do with the members of the containing class. A static method is a class method that is pointed to the class to which it belongs rather than an instance of the class. A static field is a class field, and no matter how many instances are created by the class in which the field belongs, only one instance of the field is pointed to the class to which it belongs, not an instance of the class. The initialization function is performed when the class is loaded, not when the instance is created.
4.final
Working with objects: classes, methods, fields, variables
Description: classes defined as final do not allow subclasses, cannot be overridden (not applied to dynamic queries), and field values are not allowed to be modified.
5.abstract
Working with objects: classes, interfaces, methods
Description: the class includes methods that are not implemented and cannot be instantiated. If it is an abstract method, the method body is empty, the implementation of the method is defined in the subclass, and the class that contains an abstract method must be an abstract class
6.protected
Working with objects: member
Description: a member can only be accessed in the package in which it is defined. If accessed in other packages, the class that implements this method must be a subclass of the class to which the member belongs.
7.native
Working with objects: member
Introduction: related to the operating platform, the method is not defined at the time of definition, and the implementation of the method is implemented by an external library.
8.strictfp
Working with objects: classes, methods
Description: all methods in strictfp-modified classes hide strictfp modifiers, all floating-point calculations performed by methods comply with the IEEE 754 standard, and all values, including intermediate results, must be expressed as float or double types, and cannot take advantage of the additional precision or range provided by the local platform floating-point format or hardware.
9.synchronized
Working with objects: method
Description: for a static method, jvm locks its class before execution; for a method of a non-static class, execute
Lock a specific object instance before.
10.volatile
Working with objects: field
Introduction: because asynchronous threads can access fields, some optimization operations must not work on fields. Volatile can sometimes replace synchronized.
11.transient
Working with objects: field
Description: fields are not part of the persistent state of objects and should not be concatenated with objects.
At this point, I believe you have a deeper understanding of "what are the modifiers in Java?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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
First, rely on org.springframework.cloud spring-cloud-starter-netflix-eureka-ser
© 2024 shulou.com SLNews company. All rights reserved.