About Java class variables class methods

About each variable and method

-Instance variables Refers to the field (variable) associated with each object. -Instance method Refers to the method associated with each object.

・ Class variables Refers to the fields associated with the entire class. ・ Class method Refers to the method associated with the entire class.

How to define class variables

class Car {
    public static int Car //Class variable must be static before type name public is a modifier
}Type name Class name

Class method definition method

class Car {
  public static void show(); //Class method
Method name
}
How to call the class method show () in a program that uses Car class files
Car.show();

Features of class methods

-Class methods can be called even if the object has not been created. -Instance variables and instance methods cannot be accessed in class methods.

Digression Variables declared inside a method are called local variables and cannot be used outside the declared method, and values are stored until the method ends.

class Car{
  int num;//Local variables
  static int sum;//Class variables
  void setCar(int a){//Local variables
    int a //Local variables
  }
}

Recommended Posts

About Java class variables class methods
Java class methods
About Java class
About class division (Java)
About Java StringBuilder class
[Java] About Singleton Class
About Java String class
About java abstract class
Find out about class methods
(Note) Java classes / variables / methods
About Java class loader types
Java methods
Java methods
Why are class variables needed? [Java]
Various methods of Java String class
How to use class methods [Java]
[Java] output, variables
About Java interface
[Java] About Java 12 features
[Java] Class inheritance
java Scanner class
Java HashMap class
[Java] About arrays
About class inheritance.
java (abstract class)
About singular methods
[Java] Differences between instance variables and class variables
Where about java
About HttpServlet () methods
About Java features
[WIP] Java variables
[Java] Nested class
Java anonymous class
About Java threads
[Java] About interface
About Java arrays
String class methods
About java inheritance
About interface, java interface
Java programming (static clauses and "class variables")
[java] abstract class
About Ruby variables
[Java] Object class
Java local class
About List [Java]
About java var
About Ruby methods
About Java literals
About Java commands
Ruby: Differences between class methods and instance methods, class variables and instance variables
About Java log output
About Java functional interface
Java, about 2D arrays
About the StringBuilder class
About [Java] [StreamAPI] allMatch ()
About Java method binding
[Java] About anonymous classes
About method splitting (Java)
[Java Silver] About initialization
About Ruby instance methods
About Java Array List