一个典型类的定义和UML图

时间:2021-09-24 05:51:11   收藏:0   阅读:23

【示例】模拟学生使用电脑学习

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Computer {
    String brand;  //品牌
}
public class SxtStu {
    // field
    int id;
    String sname;
    int age;
    Computer comp;
    void study() {
        System.out.println("我正在学习!使用我们的电脑,"+comp.brand);
    }
    SxtStu() {
    }
    public static void main(String[] args) {
        SxtStu stu1 = new SxtStu();
        stu1.sname = "张三";
        Computer comp1 = new Computer();
         comp1.brand = "联想";
        stu1.comp = comp1;
        stu1.study();
    }
}

  执行结果:

技术分享图片

 

  对应的UML图如下:

技术分享图片

 SxtStu和Computer的UML类图

原文:https://www.cnblogs.com/huaxiansheng/p/15310499.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!