0
0
Typescriptprogramming~5 mins

Abstract methods in Typescript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is an abstract method in TypeScript?
An abstract method is a method declared in an abstract class without an implementation. Subclasses must provide their own implementation of this method.
Click to reveal answer
beginner
Can you create an instance of an abstract class that contains abstract methods?
No, you cannot create an instance of an abstract class. Abstract classes are meant to be extended by other classes that implement the abstract methods.
Click to reveal answer
beginner
How do you declare an abstract method in TypeScript?
Use the keyword abstract before the method name and do not provide a method body. For example: abstract greet(): void;
Click to reveal answer
intermediate
Why use abstract methods in a class?
Abstract methods enforce that subclasses implement specific methods, ensuring a consistent interface while allowing different behaviors in each subclass.
Click to reveal answer
intermediate
What happens if a subclass does not implement all abstract methods from its abstract superclass?
The TypeScript compiler will give an error because the subclass must implement all abstract methods or be declared abstract itself.
Click to reveal answer
Which keyword is used to declare an abstract method in TypeScript?
Aoverride
Babstract
Cvirtual
Dinterface
Can you instantiate an abstract class directly?
ANo, never
BOnly if it has a constructor
COnly if it has no abstract methods
DYes, always
What must a subclass do if it extends an abstract class with abstract methods?
ARemove the abstract keyword
BIgnore abstract methods
CDeclare itself abstract
DImplement all abstract methods
Which of the following is true about abstract methods?
AThey have no implementation in the abstract class
BThey can be called directly on the abstract class
CThey are optional to implement in subclasses
DThey are private methods
What error occurs if a subclass does not implement an abstract method?
ASyntax error
BRuntime error
CCompiler error
DNo error
Explain what an abstract method is and why it is useful in TypeScript classes.
Think about how abstract methods guide subclasses.
You got /4 concepts.
    Describe the rules for subclassing an abstract class with abstract methods in TypeScript.
    Focus on what the subclass must do with abstract methods.
    You got /3 concepts.