类块
public class block {
public enum size {SMALL,MEDIUM,LARGE,XLARGE}
public String color;public size sz;
public block(String color, size sz) {
super();
this.color = color;
this.sz = sz;
}
public block() {
this.color="White";
this.sz=sz.SMALL;
}
public String toString() {
String result="My color is " + color + " and size=" + sz;
return result;}
类 rowOfBlock
public class rowofBlocks extends block{
private block[] blocks;
private int numofBlocks;
public rowofBlocks(int numofBlocks){
//super();
this.numofBlocks=numofBlocks;
generateBlocks() ;
}
private void generateBlocks() {
this.blocks=new block[numofBlocks];
}
public String toString() {
for(int a=0;a<blocks.length;a++)
{
System.out.print( blocks[a]);
}
String a="d";
return a;
}
}
类游戏主
public class gameMain {
public static void main(String[] args) {
block b=new block();
b.setSz(block.size.LARGE);
b.setColor("WHITE");
rowofBlocks myrows=new rowofBlocks(3);
System.out.println(b);
System.out.println(myrows);
}}
我的意思是当我尝试创建块数组时,我只看到 nullnullnulld 而不是 My color is White。