-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.
class Car {
public static int Car //Class variable must be static before type name public is a modifier
}Type name Class name
class Car {
public static void show(); //Class method
Method name
}
Car.show();
-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
}
}