public class Test {
LinkedList news=new LinkedList();
NewsTitle nt1=new NewsTitle(1,"医学","管理员");
NewsTitle nt2=new NewsTitle(2,"交通","管理员");
NewsTitle nt3=new NewsTitle(3,"计算机","管理员");
news.add(nt1);
}
public class Test {
int[] a=new int[5];
a[1]=1;
a[2]=2;
}
为什么这样会出错,news的add方法是必须要在main方法中才能调用吗?
以及第二个代码也是要在方法或者函数中才可以吗?
Syntax error on token ";", { expected after this token
Syntax error, insert ")" to complete MethodDeclaration
这两个错误在我定义数组时总是不经意出错,但是又不知道具体原因,望大神指点,不胜感激。