類方法 :是用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); // 錯誤 } }