50 lines
1.1 KiB
TypeScript
50 lines
1.1 KiB
TypeScript
//// [classAbstractUsingAbstractMethod.ts]
|
|
abstract class A {
|
|
abstract foo() : number;
|
|
}
|
|
|
|
class B extends A {
|
|
foo() { return 1; }
|
|
}
|
|
|
|
abstract class C extends A {
|
|
abstract foo() : number;
|
|
}
|
|
|
|
var a = new B;
|
|
a.foo();
|
|
|
|
a = new C; // error, cannot instantiate abstract class.
|
|
a.foo();
|
|
|
|
//// [classAbstractUsingAbstractMethod.js]
|
|
var __extends = (this && this.__extends) || function (d, b) {
|
|
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
|
function __() { this.constructor = d; }
|
|
__.prototype = b.prototype;
|
|
d.prototype = new __();
|
|
};
|
|
var A = (function () {
|
|
function A() {
|
|
}
|
|
return A;
|
|
})();
|
|
var B = (function (_super) {
|
|
__extends(B, _super);
|
|
function B() {
|
|
_super.apply(this, arguments);
|
|
}
|
|
B.prototype.foo = function () { return 1; };
|
|
return B;
|
|
})(A);
|
|
var C = (function (_super) {
|
|
__extends(C, _super);
|
|
function C() {
|
|
_super.apply(this, arguments);
|
|
}
|
|
return C;
|
|
})(A);
|
|
var a = new B;
|
|
a.foo();
|
|
a = new C; // error, cannot instantiate abstract class.
|
|
a.foo();
|