package study01; public class staticfunction { private String name; //实例成员方法:无static,归属于对象,只能由对象访问 public void study(){ System.out.println(name + "好好学习,天天向上——"); } //静态成员方法:有static修饰,属于类,可以被共享,类和对象名都可以被访问 public static int getMax(int age1,int age2){ return age1 > age2 ? age1:age2; } public static void main(String[] args) { //静态成员方法的访问1:类名.方法名 System.out.println(staticfunction.getMax(22,25)); //同一个类中静态成员方法访问不需要类名 System.out.println(getMax(98,25)); //实例成员方法访问 staticfunction a1 = new staticfunction(); a1.name = "猪八戒"; //实例成员方法:对象名.方法名 a1.study(); //静态成员方法调用2:对象名.方法名 System.out.println(a1.getMax(33,45)); } }