Home > Back-end >  JAVASE learning diary
JAVASE learning diary

Time:09-16

The static content
The use of a static method
Package test1.

Public class MyClass {

int age;//a member variable
Static int year;//static variable

//members to
Public void method () {
System. The out. Println (" this is a member of the way ");
//members method can access member variables
System. The out. Println (age);
//members method can access a static variable
System. The out. Println (year);

}

//static method
Public static void methodStatic () {
System. The out. Println (" this is a static method ");
//static method can access a static variable
System. The out. Println (year);
//static method can not access non-static variables [key]
//System. Out. Println (age).//error writing
//System. Out.println (this)//error writing


}

}

CodePudding user response:

A static method, is in the other. Don't need to import class directly used in Java code. You can use the static method

CodePudding user response:

Suggest that there is a problem to ask again and code with the right way,

CodePudding user response:

Static attribute is initialized when class loading, there are detailed introduction to https://blog.grstudy.com/java/note/19
  • Related