flutter中的继承

super

class Person {
    int age;
    string name;
    Person(int age, String name){
        this.age = age;
        this.name = name;
    }
    void sayhi(){
        print('my name is' this.name)
    }
}

class Worker extend Person{
    int salary;
    Worker(int age, string name, int salary) : super(age, name){  //super表示要继承父类的属性
        this.salary = salary;
    }
    @override  //告诉编译器和程序员他是一个重写覆盖父类的方法
    void sayhi(){
     super.sayhi()    //表示调用父类的sayhi方法 print('my salary is'+ this.salary) } }

  

上一篇:Vue.js随笔二(新建路由+component+添加样式+变量的显示)


下一篇:初步理解动态代理