Features of Static variables

What is Static?

In English, static In terms of method type, it corresponds to the type of "static method".

Variables that can be used without instantiating a class are called static variables.

Feature

Can be used with or without an instance. On the contrary, other than static, it cannot be used without an instance.

How to use static variables

First, declare as follows.

Access modifier(public etc.)static type name variable name

When a variable is declared by specifying the data type, the initial value is given.

Table of initial values

Integer: 0
float:0.0f
double type:0.0d
Character type: ’\u0000′
boolean type: false
Reference type(String):null

How to call

name of the class.Variable name

Call using the class name without instantiating the class.

What changes with static variables

You can access specified methods and member variables without new.

Example:

 public static String name = "";

    //static method
    public static String add(String , int b){
        return a + b;
    }
}

The above is usually called after instantiation (new), but by adding "static", it can be used without "new".

Summary

-Static variables are types of static variables and can be used without instantiation.

-On the contrary, other than that, it cannot be used unless it is instantiated.

Recommended Posts

Features of Static variables
Predicted Features of Java
[Java] Three features of Java
Benefits of Java static method
static
[Basic knowledge of Java] Scope of variables
[Ruby] Display the contents of variables
Item 57 Minimize the scope of local variables
Introducing the features of JavaFX SceneBuilder container
Item 57: Minimize the scope of local variables
What are the updated features of java 13
Features of spring framework for java developers
Java programming (static clauses and "class variables")