t.temp = new String[] {"temp[0]", "temp[1]"};
只是两维。。 for (int i = 0; i < 3; i++) {
try {
System.out.print (t.temp1 (i));
System.out.println (t.tt ());
} catch (Exception e) {
e.toString ();
}
}
但是输出
0,1,2三维,
所以报错
只是两维。。 for (int i = 0; i < 3; i++) {
try {
System.out.print (t.temp1 (i));
System.out.println (t.tt ());
} catch (Exception e) {
e.toString ();
}
}
但是输出
0,1,2三维,
所以报错
函数加static成静态
如果加static的话就不能用动态分配new,应如何解决?
你的方法还是不行,仍然出现这个错误:
Exception in thread "main" java.lang.NoSuchMethodError:main
import java.io.*;public class test
{
public static void main (String args[])
{
temp t = new temp ();
t.temp = new String[] {"temp[0]", "temp[1]"};
t.tt = "tt string";
for (int i = 0; i < 3; i++) {
try {
System.out.print (t.temp1 (i));
System.out.println (t.tt ());
} catch (Exception e) {
e.toString ();
}
}
} static class temp
{
public String temp[];
public String tt; public String temp1 (int i)
{
return temp[i];
} public String tt ()
{
return tt;
}
}
}
1.public static void main(String[] args)必须如此, JVM的入口.
2.static方法必须访问static成员
class 为关键字,表明java程序的任何部分都忖在于一个类中。
java的任何部分都存在类中。
static方法必须访问static成员