From e5de964ff54e6ee6b4dd02bf577e8559ab3d0c94 Mon Sep 17 00:00:00 2001 From: Jasmeet Singh Date: Thu, 4 Jul 2019 01:16:18 +0530 Subject: [PATCH] Add TypeScript 'abstract classes' guide. (#29514) * Add TypeScript 'abstract classes' guide. * fix/add-suggested-changes --- .../typescript/abstract-classes/index.md | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 guide/english/typescript/abstract-classes/index.md diff --git a/guide/english/typescript/abstract-classes/index.md b/guide/english/typescript/abstract-classes/index.md new file mode 100644 index 0000000000..f9f3998b24 --- /dev/null +++ b/guide/english/typescript/abstract-classes/index.md @@ -0,0 +1,44 @@ +--- +title: Abstract Classes +--- + +# Abstract Classes + +Abstract classes are super classes which can be derived by other classes.The class marked with the `abstract` keyword is the abstract class and it can't be instantiate directly. The Abstract class may contain `abstract` or `non-abstract` member functions. + +```typescript +abstract class FCC{ + abstract makeSkill(): void; + getSound():void{ + console.log("Coding..."); + } +} +``` + +Methods enclosed to abstract class which are marked `abstract` do not contain a method body and must be implemented in the derived class. + +```typescript +abstract class FCC{ + private name:string; + constructor(name:string){ + this.name = name; + } + abstract makeSkill(skillName:string):void; + displayName():void{ + console.log(`Hi, ${this.name} welcome to FreeCodeCamp!`); + } +} + +class Camper extends FCC{ + constructor(name:string){ + super(name); + } + makeSkill(skillName:string):void{ + console.log(`Hey, ${this.name} you made the ${skillName} skills`); + } +} + +let jack = new Camper('Jack Smith'); +jack.displayName(); +jack.makeSkill('Front-End Library'); +```