8. Dart - Inheritance Classes

 Make a default class:


class User {

    String username;

    int age;


    void printmyinfo() {

        print('$username is $age years old');

    }


    User(this.username, this.age); // constructor


}


Make a inheritance class (inherits all stuff from class above but has extra stuff):

// need to create a super constructor if the extension target class has a constructor


class UserBoss extends User {


    UserBoss(String a, int b) : super(a,b); // must be same as the variable declared in UserBoss

    // "super" is a constructor that changes the extension target classes' property

    // aand bare property variable of the UserBoss class and similar for User class


    void printbossstuff() {

        print('boss stuff');

    }

}

Comments

Popular posts from this blog

2. FreeCodeCamp - Dynamic Programming - Learn to Solve Algorithmic Problems & Coding Challenges

20. Data Analytics - Analyze Data to Answer Questions - Week 1

3. Algorithms - Selection Sort