嗨,我只是想知道提供抽象关键字之间是否有区别。
// with
abstract class A {}
class B extends A {}
// without
class A {}
class B extends A {}
我应该给吗?
答案 0 :(得分:2)
使用abstract
,您可以省略方法和getter / setter方法的实现
// with
abstract class A {
int foo();
String get bar;
set baz(String value);
}
var a = A(); // error about instantiating abstract class
class B extends A {
// error about missing implementations
}
var b = B(); // ok
// without
class A {
int foo(); // error about missing implementation
String get bar; // error about missing implementation
set baz(String value); // error about missing implementation
}
class B extends A {}