Flutter Tutorial

Inheritance

// honey/super/base
class Honey {
  int hands;
  int legs;
  int eyes;

  Honey(this.hands, this.legs, this.eyes);

  void moving() {
    print('Moving');
  }

  void eating() {
    print('Eating');
  }

  void talking() {
    print('Talking');
  }
}

// Child
class Student extends Honey {
  String institute;
  String section;

  Student(int hands, int eyes, int legs, this.institute, this.section)
      : super(hands, legs, eyes);

  @override
  void talking() {
    print('Talking politely');
  }

  @override
  void eating() {
    super.eating();
    print('Dancing while eating');
  }
}

class Teacher extends Honey {
  String institute;
  String subject;

  Teacher(super.hands, super.legs, super.eyes, this.institute, this.subject);

  @override
  void moving() {
    print('Moving with notes');
  }
}

void main() {
  Student studentOne = Student(2, 2, 2, 'NU', 'Management');
  studentOne.moving();
  studentOne.eating();
  studentOne.talking();
  print(studentOne.legs);

  Teacher englishTeacher = Teacher(2, 2, 2, 'RU', 'Accounting');
  englishTeacher.moving();
}
Scroll to Top