Can the terms "variable" and "field" be used interchangeably in java?

Studying java with several books, none of them seem to make it clear when to use this term. Now I understand it as follows:

Variables are defined in the method, and fields are part of the class.

+3
source share
6 answers

Edit:

You have the right idea.

Returning to the Java documentation, I will use their terminology :

  • Member variables in a class are fields.
  • Variables in a method or code block are local variables.
  • Variables in method declarations are parameters.

Variables refer to fields, local variables, and parameters.

+9

"" - , "". . .

+4

. . - , .

EDIT. private, protected public.

+1

, . .

+1

, , . - -, , , , , .

-1

In java, a variable is anything that can change its value during the execution period, while a field (which can also be called a member variable of a class) belongs to the class.

A constant / ending may be though (although some may disagree) as the opposite of a variable.

A Field belongs to a class and can be a variable or a constant / final.

-1
source

Source: https://habr.com/ru/post/1732903/


All Articles