类方法 :是用static 修饰的,能够直接经过类名访问java
实例方法:须要实例化一个对象,才能访问。code
例:对象
public class A{ int x,y; static float f (int a){} float g(int b){} } public class B{ public static void main(){ A a = new A(); A.f(1); // 正确; a1.f(2); // 正确; a.g(3) ; // 正确; A.f(4); // 错误 } }
////修改成//class
public class A{ int x,y; static float f (int a){} float g(int b){} } public class B{ public static void main(){ A a = new A(); A.f(1); // 正确; a.f(2); // 正确; a.g(3) ; // 正确; A.g(4); // 错误 } }