0
0
Typescriptprogramming~10 mins

Abstract classes in Typescript - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare an abstract class named Animal.

Typescript
abstract class [1] {
  abstract makeSound(): void;
}
Drag options to blanks, or click blank then click option'
AAnimal
BDog
CSound
DAnimalSound
Attempts:
3 left
💡 Hint
Common Mistakes
Using a concrete class name like 'Dog' instead of the abstract class name.
Forgetting to use the 'abstract' keyword before the class.
2fill in blank
medium

Complete the code to correctly extend the abstract class Animal.

Typescript
class Dog extends [1] {
  makeSound(): void {
    console.log('Woof!');
  }
}
Drag options to blanks, or click blank then click option'
AAnimal
BSound
CDogSound
DCreature
Attempts:
3 left
💡 Hint
Common Mistakes
Extending a class that does not exist.
Using a different class name than the abstract class.
3fill in blank
hard

Fix the error in the code by completing the blank with the correct keyword to prevent instantiation of the class.

Typescript
[1] class Animal {
  makeSound(): void {
    console.log('Some sound');
  }
}

const animal = new Animal();
Drag options to blanks, or click blank then click option'
Astatic
Bfinal
Cprivate
Dabstract
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'final' which is not a TypeScript keyword.
Using 'static' or 'private' which do not prevent instantiation.
4fill in blank
hard

Fill both blanks to declare an abstract method move in the abstract class Vehicle.

Typescript
abstract class Vehicle {
  [1] [2](): void;
}
Drag options to blanks, or click blank then click option'
Aabstract
Bmove
Crun
Dstart
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method name other than 'move'.
Not marking the method as abstract.
5fill in blank
hard

Fill all three blanks to implement the abstract method move in the subclass Car.

Typescript
class Car extends Vehicle {
  [1] [2](): void {
    console.log('[3] fast');
  }
}
Drag options to blanks, or click blank then click option'
Amove
Boverride
Cdrives
Attempts:
3 left
💡 Hint
Common Mistakes
Not using the 'override' keyword.
Using a different method name than 'move'.
Logging a wrong string.