第5章 类与对象 Java语言程序设计第2版教学课件.ppt

第5章 类与对象 Java语言程序设计第2版教学课件.ppt

例5-5 Point类的再设计 public class Point { private int x, y; public Point(int x, int y) { this.x = x; this.y = y; } public Point() { this(0,0); } public double distance(Point p) { return Math.sqrt((x-p.x)* (x-p.x) + (y-p.y)*(y-p.y)); } / * 以下两个方法在利用上面方法求距离,纯粹为了演示概念 */ public double distance2(Point p) { return this.distance(p); //调用当前对象另一方法 } public double distance3(Point p) { return p.distance(this); //p到当前点的距离 } …… } 思考: 以上程序中哪些地方可省略this ? 1、包的组织 采用分层结构 同一包中不能有两个同名的类 在缺省情况下,系统会为每一个源文件创建一个无名包 lang util awt applet even

文档评论(0)

1亿VIP精品文档

相关文档