[英]Dart Flutter What is the Difference Between Import and Extends?
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
?我的意思是,如果我只是导入类,我仍然可以使用它的构造函数和方法,那么使用
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. import
语句使该文件中的另一个类可见。
The extends
keyword makes a class inherit from another class. extends
关键字使一个类从另一个类继承。
When you say class B extends A
, B has inherited all the properties and methods of A.当你说
class B extends A
,B 已经继承了 A 的所有属性和方法。
As a reference: https://medium.com/run-dart/dart-dartlang-introduction-object-oriented-programming-c3d79d94d303作为参考: https : //medium.com/run-dart/dart-dartlang-introduction-object-oriented-programming-c3d79d94d303
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.