1. //定义一个人的接口
    2. interface Human {
    3. name: string;
    4. age: number;
    5. say(word: string): void;
    6. }
    7. //让老师类实现Human接口,老师类实现接口的时候必须提供接口的具体信息
    8. class Teacher implements Human{
    9. name = "老师";
    10. age = 38;
    11. say(word: string): void {
    12. console.log("老师说"+word)
    13. }
    14. }
    15. //让学生类实现Human接口,学生类实现接口的时候必须提供接口的具体信息
    16. class Student implements Human{
    17. name = "学生";
    18. age = 18;
    19. say(word: string): void {
    20. console.log("学生说"+word)
    21. }
    22. }