【发布时间】:2013-02-08 08:01:09
【问题描述】:
我可以使用以下代码吗?它不会在 Object 上而是在 obj.i 上抛出任何错误。这是使用对象的合法方式吗?另外,除了使用普通语法 obj s = new obj();
之外,我还有多少种方法可以创建对象?public class Test {
static int i;
static Test obj;
obj.i = 10; //am getting a compilation error here "Syntax error on token "i", VariableDeclaratorId expected after this token"
public static void main(String[] args) {
System.out.println(i+" "+ obj);
}
}
【问题讨论】:
-
你想做什么?不,只有一种方法可以初始化对象,使用
new
标签: java variables object global-variables