在创建一个类数组 [英] creating an array in a class
本文介绍了在创建一个类数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在一个Java程序编译问题:
I have a compilation problem in a Java program:
class FigureEditor {
int[] a; ----- Syntax error on token ";", , expected
a = new int[5];
}
我在做什么错了?
What am I doing wrong?
推荐答案
您不能有浮在类体内声明。
You can't have "floating" statements in the class body.
直接初始化:
int[] a = new int[5];
或使用初始化块:
int[] a;
{
a = new int[5];
}
这篇关于在创建一个类数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文