我是java的初学者求大家解释一下这段代码的意思问号的地方是疑惑的如下:

2025-03-11 11:04:25
推荐回答(3个)
回答1:

当你使用 Cell3 cell = new Cell3(1,2); 来 new对象的时候 就给了Cell的row和col赋了值.
相当于做了 Cell3 cell = new Cell3();
cell.row=1;

cell.col=2;

public Cell3(){} //这个是构造方法,一般默认了这种写法

public Cell3(int row,int col){} //也是构造方法 带参而已

回答2:

class Cell3/*类名称*/{
private int rows;//属性声明 定义行数
private int cols;//属性声明 定义列数
//在类中定义方法
public Cell3(int row,int col )//返回值类型+方法名(参数1,参数2,参数3,参数4)//构造器//构造方法?
{
this.rows=row;?//这样是否能理解?
this.cols=col; ?
}
public void drop()
{
row++;
}
} }

回答3:

你想问什么呢