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
Post a Comment