static

I am a beginner, but I summarized it for personal study

** Static **

** After loading **, the static contents of the class file are placed in the memory area called ** static area **, and the others are placed in the ** heap area **. ** Class variables ** and ** class methods ** placed in the static area are positioned as one in the class. No matter how many instances are created from that class, member variables and methods are not assigned to each instance, and only one data is created. Therefore, ** all instances share the same value **, so you can use it without creating an instance **

** * Load ** ・ ・ ・ Reading a class file

** * Class variables, class methods ** ・ ・ ・ Those with static qualifiers ** Class variables **, ** Class methods **, those without static qualifiers ** Instance variables Called **, ** instance method **

static access

Static members can be used with or without an instance, but non-static members cannot be used without an instance Due to this rule, static methods can only be accessed ** statically qualified **

static field

・ There are two ways to access ① ** Class name. Field name ** (2) ** Variable name.Field name ** after instance creation

・ There are two ways to initialize ① Set the value at the time of declaration ② Set the value with ** static initializer **

** * static initializer ** -Blocks that are executed only once at load time only with the static modifier -Describe the process you want to call and execute before instantiating a certain class or before the main method

static method (class method)

-Static method belongs to the class and performs the specified process regardless of the state of the instance, so it is often used to implement the process that is used for general purposes.

·how to access ① Call ** Class name. Method name (argument, ...) ** (2) Refer to the method of the functional interface ** Class name :: Method name (argument, ...) **

Recommended Posts

static
static variable
Java static
About static
static modifier
Java static story
Static uncle's counterattack
[Terms] Static and dynamic
Java static [Personal summary]
static factory method part 1
Features of Static variables