0
0
Javascriptprogramming~5 mins

Inheritance using classes in Javascript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is inheritance in JavaScript classes?
Inheritance allows a class (child) to use properties and methods from another class (parent), helping to reuse code and create relationships between classes.
Click to reveal answer
beginner
How do you create a child class that inherits from a parent class in JavaScript?
Use the <code>extends</code> keyword in the child class declaration, like <code>class Child extends Parent {}</code>.
Click to reveal answer
intermediate
What is the purpose of the <code>super()</code> function in a child class constructor?
<code>super()</code> calls the parent class constructor. It must be called before using <code>this</code> in the child constructor to properly initialize the parent part.
Click to reveal answer
intermediate
Can a child class override a method from its parent class? How?
Yes, by defining a method with the same name in the child class, it replaces the parent's method when called on child instances.
Click to reveal answer
beginner
What happens if you call a method on a child class instance that is not defined in the child but exists in the parent?
The method from the parent class is used, showing how inheritance allows child classes to access parent methods if not overridden.
Click to reveal answer
Which keyword is used to make a class inherit from another class in JavaScript?
Aextends
Binherits
Cimplements
Dsuper
What must you call inside a child class constructor before using this?
Athis()
Bparent()
Csuper()
Dconstructor()
If a child class has a method with the same name as the parent, which method runs when called on the child?
AParent's method
BError occurs
CBoth methods run
DChild's method
What happens if a method is called on a child instance but only exists in the parent?
AError: method not found
BParent's method runs
CChild's method runs
DNothing happens
Which of these is NOT true about inheritance in JavaScript classes?
AChild classes must redefine all parent methods
BChild classes can override parent methods
CChild classes can reuse parent methods
DChild classes use <code>extends</code> keyword
Explain how inheritance works in JavaScript classes and why it is useful.
Think about how a child class can get features from a parent class.
You got /5 concepts.
    Describe the role of the super() function in a child class constructor.
    Consider what happens when you create a child object that needs parent setup.
    You got /3 concepts.