Recall & Review
beginner
What does it mean to extend a class in TypeScript?Extending a class means creating a new class that inherits properties and methods from an existing class. This helps reuse code and add new features.Click to reveal answer
beginner
How do you specify the type of a class property when extending a class?You declare the property with its type in the class definition. When extending, you can keep the same type or specify a more specific type if needed.Click to reveal answer
beginner
What is the syntax to extend a class named <code>Animal</code> in TypeScript?Use <code>class Dog extends Animal { }</code> to create a new class <code>Dog</code> that inherits from <code>Animal</code>.Click to reveal answer
intermediate
Can a subclass override a method from its superclass in TypeScript? How?Yes, a subclass can provide its own version of a method by defining a method with the same name. This replaces the superclass method when called on the subclass instance.Click to reveal answer
intermediate
How do you call the constructor of a superclass inside a subclass in TypeScript?Use the <code>super()</code> function inside the subclass constructor to call the superclass constructor and pass any required arguments.Click to reveal answer
What keyword is used to create a class that inherits from another class in TypeScript?
✗ Incorrect
The keyword
extends is used to create a subclass that inherits from a superclass.How do you specify the type of a property in a TypeScript class?
✗ Incorrect
In TypeScript, you specify a property type using
propertyName: type; syntax.Which method allows a subclass to use the constructor of its superclass?
✗ Incorrect
The
super() function calls the superclass constructor inside the subclass constructor.If a subclass defines a method with the same name as its superclass, what happens?
✗ Incorrect
The subclass method replaces the superclass method when called on subclass instances.
Can a subclass add new properties not present in the superclass?
✗ Incorrect
Subclasses can add new properties and methods beyond what the superclass has.
Explain how extending classes works in TypeScript and why it is useful.
Think about how a new class can get features from an existing class.
You got /5 concepts.
Describe how to override a method in a subclass and how to call the superclass constructor.
Focus on how subclasses change behavior and initialize.
You got /4 concepts.