0
0
Typescriptprogramming~5 mins

Abstract classes in Typescript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is an abstract class in TypeScript?
An abstract class is a class that cannot be instantiated directly. It is meant to be a base class for other classes and can contain abstract methods that must be implemented by subclasses.
Click to reveal answer
beginner
Can you create an object from an abstract class?
No, you cannot create an object directly from an abstract class. You must create an object from a subclass that extends the abstract class and implements its abstract methods.
Click to reveal answer
beginner
What is an abstract method?
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
How do you declare an abstract class and an abstract method in TypeScript?
Use the keyword <code>abstract</code> before the class name to declare an abstract class. Use <code>abstract</code> before a method signature inside the class to declare an abstract method.
Click to reveal answer
intermediate
Why use abstract classes instead of interfaces in TypeScript?
Abstract classes can have both implemented methods and abstract methods, allowing shared code and enforced method implementation. Interfaces only declare method signatures without implementation.
Click to reveal answer
Which keyword is used to declare an abstract class in TypeScript?
Aabstract
Binterface
Cclass
Dimplements
Can you instantiate an abstract class directly?
AYes, always
BNo, never
COnly if it has no abstract methods
DOnly inside subclasses
What must a subclass do if it extends an abstract class with abstract methods?
AOverride only some abstract methods
BIgnore abstract methods
CImplement all abstract methods
DConvert abstract methods to properties
Which of these can an abstract class contain?
ABoth abstract and implemented methods
BOnly implemented methods
COnly properties
DOnly abstract methods
What happens if a subclass does not implement all abstract methods?
AIt automatically implements methods
BIt compiles without errors
CIt throws a runtime error
DIt becomes an abstract class itself
Explain what an abstract class is and why you would use it in TypeScript.
Think about a blueprint that cannot be built but guides other buildings.
You got /4 concepts.
    Describe the difference between an abstract class and an interface in TypeScript.
    One can have code inside, the other only rules.
    You got /4 concepts.