如何在java中用布尔值编写构造函数?
我的代码如下所示:
public class Cell {
private boolean north;
private boolean east;
private boolean south;
private boolean west;
/** Construct a Cell, using the parameters given to initialize
* the wall instance variables.
*
* @param north
* @param south
* @param east
* @param west
*/
public Cell(boolean north, boolean east, boolean south, boolean west) {
?
}
如何使用布尔值编写构造函数?谢谢
# 1 楼答案
boolean
没有什么不同,您可以类似于以下其他类型初始化它们: 您必须使用关键字this
(即解析阴影)来引用字段变量,因为参数变量与字段具有相同的名称