类
类的定义
类之间的关系
泛化
动物是老虎的泛化
实现
关联
是一种拥有关系,可以使双向的,也可以是单向的
聚合关系
是整体和部分的关系,且部分离开整体依然可以单独存在
聚合关系
是整体与部分的关系,但部分不能离开整体而单独存在
依赖
是一种使用关系,即一个类的实现需要另一个类的协助
各种关系的强弱顺序
声明Java类
(有可能有父类extends)
this指针
级联
相当于将多个表中同一数据串起来,変一个就都变
操作示例
import java.awt.*;
import java.applet.*;
public class Ch05_3_1 extends Applet {
private Color []color = {Color.RED,Color.BLUE,
Color.GREEN,Color.ORANGE,
Color.PINK};
private int width,height;
private int d;
public void init(){
}
public void paint(Graphics g){
int x,y,i;
width = getWidth();
height = getHeight();
d = ((width>height? height:width))/5;
public void paint(Graphics g){
int x,y,i;
width = getWidth();
height = getHeight();
d = ((width>height? height:width))/5;
x = 0;
y = 0;
width = (width>height? height:width);
for(i=0;i<5;i++){
g.setColor(color[i]);
g.drawArc(x,y,width,width,0,360);
width = width - d;
x = x + d;
y = y + d;
}
}
}
抽象类