JAVA is an object-oriented language,all things can be objects(saved in a class)
The method can't exist dependently in JAVA,we can only define it in a class
The static method
- A static method
The static method is attached to th e class itself,and it will be loaded first compared with instance method
public class Person(){
public ***static*** void test(){
}
}
This is a special defination mode,because its existence is along with the establishment of this Class--Person.
So we can only ues Person to invoke it.
public class Myclass(){
Person.test(){
}
The instance method(實例方法)
The object method is attached to the object,we must establish an object of this class,and use it to invoke the object method.
public class Person(){
public void eat(){
}
}
public class Myclass(){
person.p1 = new Person();
p1.eat();
}
靜態(tài)方法.png