标签:math类 没有 创建 ati nbsp prime 不能 其他 span
静态方法(全局方法):既没有访问this的属性,也没有访问this的方法,是一种特殊的方法
特点:该方法可以拷贝到其他类中,它是独立的通用的
在Java中,静态方法用static修饰
例如:
public class MyTest
{
public static boolean isPrime( int n )
{
。。。 // 算法
}
}
注:静态方法里不能访问this,它跟类没有关系
调用静态方法时,不需要创建对象,直接调用方法,与对象无关
例如:
boolean result = MyTest.isPrime(123);
Java中自带的类诸如 String,Math ,这些类中的方法就是静态方法,直接使用。
例如:
Math.abs(-222); // 直接使用Math类的方法,不需要创建Math对象,就是静态方法
标签:math类 没有 创建 ati nbsp prime 不能 其他 span
原文地址:https://www.cnblogs.com/yangwu-183/p/10204530.html