search
HomeJavajavaTutorialWhat are the modifiers in Java?

What are the modifiers in Java?

May 09, 2023 am 11:25 AM
java

The Java language defines 6 commonly used modifiers, including public, protected, private, abstract, static and final, and 5 less commonly used modifiers. The following is an introduction to these 11 Java modifiers:
1.public

Use objects: classes, interfaces, members

Introduction: No matter where the package it is in is defined, the class (interface, member) is accessible

2.private

Use object: member

Introduction: member can only be accessed in the class in which it is defined

3.static

Use objects: classes, methods, fields, initialization functions

Introduction: The inner class named static is a top-level class, which is not related to the members of the containing class. Static methods are class methods that are pointed to the class to which they belong rather than to instances of the class. A static field is a class field. No matter how many instances are created by the class in which the field is located, there is only one instance of the field that points to the class it belongs to rather than an instance of the class. The initialization function is executed when the class is loaded, not when the instance is created.

4.final

Used objects: classes, methods, fields, variables

Introduction: A class defined as final does not allow subclasses and cannot be overwritten (not Applied to dynamic queries), field values ​​are not allowed to be modified.

5.abstract

Used objects: classes, interfaces, methods

Introduction: Classes include unimplemented methods 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 containing an abstract method must be an abstract class

6.protected

Usage object: member

Introduction: A member can only be accessed in the package in which it is defined. If it is accessed in other packages, the class that implements this method must be a subclass of the class to which the member belongs.

7.native

Used object: member

Introduction: It is related to the operating platform. Its method is not defined when it is defined. The implementation of the method is implemented by an external library.

8.strictfp

Use objects: classes, methods

Introduction: All methods in classes modified by strictfp hide the strictfp modifier, and all floating points executed by the method Calculations comply with the IEEE 754 standard. All values, including intermediate results, must be represented as float or double types, without taking advantage of the additional precision or representation range provided by the native platform floating point format or hardware.

9.synchronized

Use object: method

Introduction: For a static method, the jvm locks the class it is in before execution; for a non-static class Method, lock a specific object instance before executing

.

10.volatile

Using objects: fields

Introduction: Because asynchronous threads can access fields, some optimization operations must not be applied to fields. volatile can sometimes replace synchronized.

11.transient

Using objects: fields

Introduction: Fields are not part of the persistent state of the object, and fields should not be strung together with the object.

The above is the detailed content of What are the modifiers in Java?. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:亿速云. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment