Complete the code to extend the base class correctly.
class Animal { name: string; constructor(name: string) { this.name = name; } } class Dog extends [1] { bark() { return `Woof! I am ${this.name}`; } }
The Dog class extends the Animal class to inherit its properties and methods.
Complete the code to add a type to the extended class property.
class Vehicle { wheels: number; constructor(wheels: number) { this.wheels = wheels; } } class Car extends Vehicle { model: [1]; constructor(wheels: number, model: string) { super(wheels); this.model = model; } }
number or boolean for a text property.any when a specific type is better.The model property is a string, so its type should be string.
Fix the error in the constructor to call the parent class correctly.
class Person { age: number; constructor(age: number) { this.age = age; } } class Employee extends Person { salary: number; constructor(age: number, salary: number) { [1]; this.salary = salary; } }
super() without arguments causes an error.super.salary which is invalid.The super call must pass the age parameter to the parent constructor.
Fill both blanks to create a generic class that extends another generic class.
class Box<T> { content: T; constructor(content: T) { this.content = content; } } class ColoredBox<[1]> extends Box<[2]> { color: string; constructor(content: [2], color: string) { super(content); this.color = color; } }
The generic type parameter T is used consistently in both the subclass and the superclass.
Fill all three blanks to extend an interface with a class and add a new method.
interface Logger {
log(message: string): void;
}
class ConsoleLogger implements [1] {
[2](message: string): void {
console.log(message);
}
[3](): void {
console.log('Logging complete');
}
}implements.The class implements the Logger interface, defines the log method, and adds a new finish method.
