I still do not understand the difference between importing a class and extending a class. I mean if I just import the class I can still use its constructor and methods, so what is the advantage of using extends
?
Feel free to use the two classes I provided or change them to your convenience.
Class A {
final String a;
A({this.a});
void printA(){
print(this.a);
}
}
Class B {
final String b;
B({this.b});
void printB(){
print(this.b);
}
}
An import
statement makes another class visible in that file.
The extends
keyword makes a class inherit from another class.
When you say class B extends A
, B has inherited all the properties and methods of A.
As a reference: https://medium.com/run-dart/dart-dartlang-introduction-object-oriented-programming-c3d79d94d303
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.