Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare an abstract method named display.
Typescript
abstract class Vehicle { abstract [1](): void; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different method name than
display.Trying to provide a method body in the abstract method.
✗ Incorrect
The abstract method must be declared with the exact name
display as required.2fill in blank
mediumComplete the code to make Vehicle an abstract class.
Typescript
abstract class [1] { abstract display(): void; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different class name than
Vehicle.Not declaring the class as abstract (though not asked here).
✗ Incorrect
The class must be named
Vehicle to match the abstract method declaration context.3fill in blank
hardFix the error in the subclass by correctly implementing the abstract method display.
Typescript
abstract class Vehicle { abstract display(): void; } class Car extends Vehicle { [1] display(): void { console.log('Car display'); } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
abstract keyword in subclass method implementation.Using
private which restricts access and causes errors.✗ Incorrect
The method must be declared
public to correctly implement the abstract method from the base class.4fill in blank
hardFill both blanks to declare an abstract method calculateSpeed that returns a number.
Typescript
abstract class Vehicle { abstract [1](): [2]; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong return type like
string or void.Using a different method name.
✗ Incorrect
The method name is
calculateSpeed and it returns a number type.5fill in blank
hardFill all three blanks to implement the abstract method calculateSpeed in subclass Bike that returns a number.
Typescript
abstract class Vehicle { abstract calculateSpeed(): number; } class Bike extends Vehicle { [1] [2](): [3] { return 50; } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
void as return type instead of number.Using wrong method name or missing access modifier.
✗ Incorrect
The method must be declared
public, named calculateSpeed, and return type number.