0
0
Typescriptprogramming~5 mins

Super keyword behavior in Typescript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the super keyword do in TypeScript classes?
The super keyword is used to call functions on an object's parent class. It allows access to the parent class's constructor and methods.
Click to reveal answer
beginner
When must you call <code>super()</code> in a derived class constructor?
You must call <code>super()</code> before using <code>this</code> in a derived class constructor. This ensures the parent class is properly initialized first.
Click to reveal answer
intermediate
How do you use <code>super</code> to call a parent class method that is overridden?
Inside the child class method, use <code>super.methodName()</code> to call the parent class's version of the method.
Click to reveal answer
intermediate
Can <code>super</code> be used outside of class methods or constructors?
No, <code>super</code> can only be used inside class constructors or methods to refer to the parent class. Using it outside causes errors.
Click to reveal answer
beginner
What happens if you forget to call <code>super()</code> in a derived class constructor?
TypeScript will throw an error because the parent class constructor must be called before accessing <code>this</code>. This prevents incomplete initialization.
Click to reveal answer
What is the purpose of the super() call in a derived class constructor?
ATo override a method
BTo create a new instance of the child class
CTo call a static method
DTo initialize the parent class before using <code>this</code>
How do you call a parent class method named greet from a child class?
A<code>super.greet()</code>
B<code>this.greet()</code>
C<code>parent.greet()</code>
D<code>greet.super()</code>
Can you use super outside of a class method or constructor?
AYes, anywhere in the code
BNo, only inside class methods or constructors
COnly inside static methods
DOnly inside arrow functions
What error occurs if you use this before super() in a derived class constructor?
AReferenceError
BSyntaxError
CTypeError
DNo error
Which statement about super is true?
A<code>super</code> is a variable holding the parent class
B<code>super</code> creates a new instance of the parent class
C<code>super</code> can be used to access parent class properties and methods
D<code>super</code> can be used in any function
Explain how and why you use the super keyword in a TypeScript class constructor.
Think about what happens when you create a child class object.
You got /3 concepts.
    Describe how to call a parent class method from a child class when the method is overridden.
    How do you reach back to the original method?
    You got /3 concepts.