OOP – Inheritance (extends)

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

OOP – Inheritance (extends)

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Does extends let a class inherit from another class?
A Yes
B No
2. Does super() call the parent class's constructor?
A Yes
B No
3. Is 'Extends' with a capital E valid JavaScript syntax?
A No
B Yes
4. Must 'super' be written in lowercase?
A No
B Yes
5. Is 'extend' (without an s) the correct keyword?
A Yes
B No

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1class Dog extends Animal { ... } AWrong - 'super' must be lowercase
2super(name); Bextends
3Lets one class inherit properties and methods from another CWrong - 'extends' must be lowercase
4Calls the parent class's constructor inside a child class DCalls the parent class's constructor with name
5class Dog Extends Animal { ... } EDeclares Dog as a subclass that inherits from Animal
6Super(name); Fsuper()

Definitions

extends

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
class Dog _______ Animal {
2.
_____(name);
3.
class Cat _______ Animal {
4.
constructor(name) { _____(name); }
5.
class Puppy _______ Dog {

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A Class Ant extends Animal {
B constructor(name) {
C super(name);
D }
E }
Question 2
A clas Bee extends Animal {
B constructor(name) {
C super(name);
D }
E }
Question 3
A let name = "Rex";
B class Fox Extends Animal {
C constructor(name) {
D super(name);
E }
F }
Question 4
A let name2 = "Tom";
B class Owl extend Animal {
C constructor(name) {
D super(name);
E }
F }
Question 5
A class Bear extends Animal {
B constructor(name) {
C Super(name);
D }
E }

Answer Key

OOP – Inheritance (extends)
Section A: Quick Questions
Q1
A — Yes
Q2
A — Yes
Q3
A — No
Q4
B — Yes
Q5
B — No
Section B: Match the Pairs
Q1
class Dog extends Animal { ... } → Declares Dog as a subclass that inherits from Animal
Q2
super(name); → Calls the parent class's constructor with name
Q3
Lets one class inherit properties and methods from another → extends
Q4
Calls the parent class's constructor inside a child class → super()
Q5
class Dog Extends Animal { ... } → Wrong - 'extends' must be lowercase
Q6
Super(name); → Wrong - 'super' must be lowercase
Section C: Definitions
Q1
extends — Lets a class inherit properties and methods from another class.
Section D: Fill in the Blanks
Q1
class Dog extends Animal {
Q2
super(name);
Q3
class Cat extends Animal {
Q4
constructor(name) { super(name); }
Q5
class Puppy extends Dog {
Section E: Spot the Error
Q1
A — 'class' must be lowercase - a capital C causes an error.
Q2
A — 'class' is misspelled as 'clas'.
Q3
B — 'extends' must be lowercase - a capital E causes an error.
Q4
B — 'extends' is misspelled as 'extend'.
Q5
C — 'super' must be lowercase - a capital S causes an error.