方法的调用(类方法和成员方法)
public class Test1 { public static void main(String[] args) { int show = show();//直接调用 System.out.println("类方法:"+show);
int add = Student.add(11, 12);//类名.调用 System.out.println("非本类的类方法:"+add);
int multiply = new Student().multiply(1, 4);//实例化对象调用 System.out.println("非本类的成员方法:"+multiply); Test1 t1=new Test1();//实例化对象调用 System.out.println("subtract方法:"+t1.subtract(22,4)); } public static int show(){ int a=2; return a; } public int subtract(int a, int b){ return a-b; } } class Student{ public static int add(int a,int b){ return a+b; } public int multiply(int a,int b){ return a*b; } }