Java非静态变量或方法在main方法中需要通过( )访问?

如题所述

在静态方法中调用非静态方法,需要实例一下对象,在用对象点方法来调用,属性一样
public class TestApplication
{
public static void main(String[] args) {
TestApplication test = new TestApplication();
test.testMethod();

}
public String testMethod(){
System.out.println("这是一个测试方法”);

}
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2020-02-24
new 对象后,对象.变量,对象.方法。
因为static中不能直接访问非静态变量或方法
第2个回答  2020-02-24
实列化对象就可以调用啦
相似回答