Home  >  Article  >  Java  >  How to call variables in java

How to call variables in java

尚
Original
2019-12-27 10:21:404769browse

How to call variables in java

In the Java language, all variables must be declared before use. The basic format for declaring variables is as follows:

type identifier [ = value][, identifier [= value] ...] ;

Format description: type is a Java data type. identifier is the variable name. Multiple variables of the same type can be declared separated by commas.

There are several methods to call variables of other classes in java:

Method 1:

new When an object of other classes comes out, call the Public variables of the class (public)

Method 2:

Set the variables of other classes to public static, that is, static public variables, which can be obtained directly using the class name.variable name. However, this method is best used only for basic data variables (int/long/boolean/double/byte, etc.), otherwise it will cause memory leaks.

Method 3:

Use methods or interfaces to pass this variable from other classes.

For more java knowledge, please pay attention to the java basic tutorial column.

The above is the detailed content of How to call variables in java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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