JAVA面向对象摘要.doc

1.类包括行为和特征,可以包括多个对象(结构相同,数据不同) 2.创建类 包括成员变量和方法 特征为成员变量,行为为方法 3.创建对象语法: 类名 引用=new 类名(); 其中:new类名()是在创建对象 因对象为数据,所有声明引用来指代数据 4.访问成员变量,访问方法语法: 引用.成员变量 引用.方法名(); cStdent 创建Cell类: public class Cell { int row; int col; Cell(int row,int col){ this.row=row; this.col=col; } Cell(int n){ row=n; col=n; } Cell(){ this(3,3); } void drop(){ row++; } void moveLeft(int n){ col-=n; } void moveRight(int m){ col+=m; } String getcellInfo(){ return (+row+,+col+); } } 创建CellTest测试类 public class CellTest { public static void main(String[] args) { Cell c=new Cell(4,4); c.drop(); print(c); c.moveLeft(3); c.moveRight(

文档评论(0)

1亿VIP精品文档

相关文档