public class HelloDate { String s="intital value";
public static void main(String[] args){
System.out.println(s);
}
}为什么这个不可以啊,编译之后出现如下提示:Exception in thread "main" java.lang.Error: Unresolved compilation problem: Cannot make a static reference to the non-static field s at HelloDate.main
public static void main(String[] args){
System.out.println(s);
}
}为什么这个不可以啊,编译之后出现如下提示:Exception in thread "main" java.lang.Error: Unresolved compilation problem: Cannot make a static reference to the non-static field s at HelloDate.main
public class HelloDate { public static void main(String[] args){
String s="intital value";
System.out.println(s); }
} 这样
是没有办法使用s的public class HelloDate {public String s="intital value";public static void main(String[] args){
HelloDate test=new HelloDate();
System.out.println(test.s);}
} 这样倒是可以
String s="intital value"; 改成静态的应该就没什么问题
static String s="intital value";
HelloDate test=new HelloDate();
这个是产生个对象···
我说的那个不会不可以吧,我都试过了另外把String直接改成static的也是可以的
相反则可以.....
可以把String定义为静态的。。