有 static 和 无 static
public class Demo16 {
public static void main(String[] args) {
// 调用静态方法
Person.say(); // 学生说悄悄话!
// 调用非静态方法
new Person().play(); // 学生在玩耍!
// 或者
Person person = new Person();
person.play(); // 学生在玩耍!
}
}
// 学生类
public class Person {
// 静态方法
public static void say(){
System.out.println("学生说悄悄话!");
}
// 非静态方法
public void play(){
System.out.println("学生在玩耍!");
}
}