0
0
Typescriptprogramming~5 mins

Extending classes with types in Typescript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Ainherits
Bimplements
Csuper
Dextends
How do you specify the type of a property in a TypeScript class?
ApropertyName: type;
BpropertyName = type;
Ctype propertyName;
DpropertyName -> type;
Which method allows a subclass to use the constructor of its superclass?
Athis()
Bsuper()
Cparent()
Dbase()
If a subclass defines a method with the same name as its superclass, what happens?
AThe subclass method overrides the superclass method.
BBoth methods run automatically.
CThe superclass method is called instead.
DAn error occurs.
Can a subclass add new properties not present in the superclass?
ANo, subclasses must have the same properties.
BOnly if the superclass allows it.
CYes, subclasses can add new properties.
DOnly if the subclass is abstract.
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.