Home > Java > Java Tutorial > body text

What modifiers cannot be used in top-level declarations in JShell in Java 9?

王林
Release: 2023-08-20 16:25:02
forward
912 people have browsed it

在Java 9的JShell中,不能在顶层声明中使用哪些修饰符?

JShell is an interactive tool for learning the Java language and prototyping Java code. It is a REPL (Read-Evaluate-Print-Loop) that immediately evaluates statements, statements and expressions## once entered. #, and print the results immediately in JShell. This tool is run from the command line prompt.

Modifiers like

public, protected, private, static, and final Not allowed in top-level declarations, and may be ignored with a warning. Keywords like synchronized, native, abstract, and default top-level methods are not allowed and may raise mistake.

In the code snippet below, we create

final and static variables. It prints a warning message to the user that reads "Modifier 'final' or 'static' not permitted in top-level declarations, ignored". The Chinese translation of

Example-1

C:\Users\User\>jshell
| Welcome to JShell -- Version 9.0.4
| For an introduction type: /help intro

jshell> final int x = 0
| Warning:
| Modifier 'final' not permitted in top-level declarations, ignored
| final int x = 0;
| ^---^
x ==> 0

jshell> x = 1
x ==> 1
Copy after login

Example-2

is:

Example-2

jshell> static String str = "Tutorix"
| Warning:
| Modifier 'static' not permitted in top-level declarations, ignored
| static String str = "Tutorix";
| ^----^
str ==> "Tutorix"
Copy after login

The above is the detailed content of What modifiers cannot be used in top-level declarations in JShell in Java 9?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!