UML类图--实现关系

实现关系-Realization:类与接口的关系,代表类实现了接口的所有属性和方法。

  • UML展示:

箭头指向:带三角箭头的虚线,箭头指向接口。

  • 代码实现:
// 测试类
public class RealizationTest {
    public static void main(String[] args) {
        Student student = new StudentImpl();
        student.runing();
        student.speaking();
    }
}
// 接口
interface Student {
    void speaking();
    void runing();
}
// 接口实现类
class StudentImpl implements Student {

    private String name;

    public void speaking() {
        System.out.println("学生开始说汉语。");
    }

    public void runing() {
        System.out.println("学生进行跑步运动。");
    }

}

 


版权声明:本文为yhy_it原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。