java - creating array of objects -
i try create array object stock, wrote code create stock object s , add array.
private stock s = new stock("name", "price", 22); stock[] d =new stock[2]; d[0]= s; d[1]= s;
i these errors :
']' expected d[0]= s; illegal start of type d[0]= s;
if you're outside method, you'll need initializer block (or use constructor) -
private stock s = new stock("name", "price", 22); private stock[] d = new stock[2]; { d[0] = s; d[1] = s; }
if you're inside method, can -
stock s = new stock("name", "price", 22); stock[] d = new stock[2]; d[0] = s; d[1] = s; // stock[] d = new stock[] { s, s }; // <-- or
Comments
Post a Comment