OOP – Classes & Objects

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

OOP – Classes & Objects

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Does class declare a blueprint for creating objects?
A Yes
B No
2. Does new create an instance of a class?
A No
B Yes
3. Must 'class' be written in lowercase?
A Yes
B No
4. Must 'new' be written in lowercase?
A Yes
B No
5. Is 'Class' with a capital C valid JavaScript syntax?
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 { name = "Rex"; } AWrong - 'class' must be lowercase
2new Dog() Bclass
3Declares a reusable blueprint for creating objects CWrong - 'new' must be lowercase
4Creates an instance of a class DCreates a new instance of the Dog class
5Class Dog { name = "Rex"; } EDeclares a blueprint for creating Dog objects
6let d = New Dog(); Fnew

Definitions

class

Fill in the Blanks

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

1.
_____ Dog {
2.
let myDog = ___ Dog();
3.
class Cat _
4.
let c = ___ Cat();
5.
class Bird _

Spot the Error

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

Question 1
A Class Dog {
B name = "Rex";
C }
Question 2
A class Cat {
B name = "Tom"
C }
Question 3
A class Bird {
B name = "Tweety";
C ]
Question 4
A class Fish {
B name = "Nemo";
C }
D let f = New Fish();
Question 5
A clas Dog {
B name = "Rex";
C }

Answer Key

OOP – Classes & Objects
Section A: Quick Questions
Q1
A — Yes
Q2
B — Yes
Q3
A — Yes
Q4
A — Yes
Q5
B — No
Section B: Match the Pairs
Q1
class Dog { name = "Rex"; } → Declares a blueprint for creating Dog objects
Q2
new Dog() → Creates a new instance of the Dog class
Q3
Declares a reusable blueprint for creating objects → class
Q4
Creates an instance of a class → new
Q5
Class Dog { name = "Rex"; } → Wrong - 'class' must be lowercase
Q6
let d = New Dog(); → Wrong - 'new' must be lowercase
Section C: Definitions
Q1
class — Declares a blueprint for creating objects with shared properties and methods.
Section D: Fill in the Blanks
Q1
class Dog {
Q2
let myDog = new Dog();
Q3
class Cat {
Q4
let c = new Cat();
Q5
class Bird {
Section E: Spot the Error
Q1
A — 'class' must be lowercase - a capital C causes an error.
Q2
B — This line is missing a semicolon, but that's not required in JS.
Q3
C — The class body must close with }, not ].
Q4
D — 'new' must be lowercase - a capital N causes an error.
Q5
A — 'class' is misspelled as 'clas'.