A variable is the name of a memory location.
1. member variables (instance variables, attributes)
A member variable is a property in a class, and each object has a copy of the property when the object is created. A property in an object is a member variable.
2. Local variables (local variables)
A variable declared within a method is called a local variable, and only that method can access it.
3. Class variables (static variables)
staticthe variable declared is called a static variable and cannot be declared as local. You can use the class name. Property Access.
Example:
class Person { int : age =; //Member variables Static // Static Variables void eat () { int n = +; // Local Variables }}
A variable cannot be a system-reserved keyword:
For example:
int Private // this is not allowed.
Schedule: Java system reserved Keywords
|
Access control |
Private |
Protected |
Public |
|
|
|
|
|
|
|
classes, methods, and variables
modifier |
abstract |
class |
extends |
Final |
Implements |
interface |
native |
new |
static |
|
strictfp |
Synchronized |
transient |
volatile |
  |
  |
  |
  |
  |
|
Program Control |
break |
Continue |
return |
do |
while |
if |
Else |
for |
instanceof |
|
switch |
Case |
default |
  |
  |
  |
  |
  |
  |
|
error handling |
Try
|
Catch |
Throw |
throws |
  |
  |
  |
  |
  |
|
Package related |
Import |
Package |
  |
  |
  |
  |
  |
  |
  |
|
Basic type |
Boolean |
Byte |
Char |
Double |
float |
int |
Long |
Short |
Null |
| True
|
False |
  |
  |
  |
  |
  |
  |
  |
|
variable reference |
Super |
This |
void |
  |
  |
  |
  |
  |
  |
|
Reserved words |
Goto |
Const |
|
|
|
|
|
|
|
Variables for the Java Foundation