如何在不提及类名的情况下调用静态方法?.ex-below
class Test {
public static void staticMethodOne() {
System.out.println("Static method one");
}
public void instanceMethodOne() {
staticMethodOne();//Call static method without mentioning the class
//name
Test.staticMethodOne();//call from class name
new Test().staticMethodOne();//calling from object ref
}
public static void staticMethodTwo() {
staticMethodOne();
}
}
最佳答案
由于您是在同一个类中访问它,因此不需要像任何其他实例方法一样需要实例。
关于java - 如何在不提及类名的情况下调用静态方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49007919/