【发布时间】:2018-09-25 18:31:00
【问题描述】:
我到处寻找,但没有找到与在类构造函数中初始化数组相关的任何内容。
这是我要创建的类:
public Sandwich(char b, String m, String c, String[] e)
{
setBread( b );
setMeat( m );
setCheese( c );
setExtras( e );
}
这是我初始化数组的尝试:
public static void main(String[] args)
{
Sandwich[] order;
order = new Sandwich[3];
order[0] = new Sandwich('s', "pastrami", "swiss", extras[2] = {"mayo", "extra meat"} )
order[1] = new Sandwich();
}
我很茫然。
【问题讨论】:
标签: java arrays class constructor initialization