OOP – Methods

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

OOP – Methods

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Is a method a function declared inside a class body?
A No
B Yes
2. Do class methods use the 'function' keyword?
A Yes
B No
3. Is a method called on an instance using dot notation?
A Yes
B No
4. Does calling a method require parentheses?
A Yes
B No
5. Can 'this' be used inside a method to access the instance's properties?
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
1bark() { console.log(this.name + " says woof"); } AWrong - calling a method needs parentheses
2myDog.bark(); BCalls the bark method on the myDog instance
3A function declared inside a class, without 'function' CDeclares a method that prints the dog's name and a sound
4Refers to the instance a method is called on DWrong - class methods don't use the 'function' keyword
5function bark() { console.log("woof"); } Ethis
6myDog.bark; Fshow() { ... }

Definitions

method

Fill in the Blanks

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

1.
____() { console.log(this.name + " says woof"); }
2.
myDog.____();
3.
____() { console.log(this.color); }
4.
myCar.____();
5.
console.log(____.name + " says woof");

Spot the Error

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

Question 1
A myDog.Bark();
B let myDog = new Dog();
C class Dog {
D bark() { console.log(1); }
E }
Question 2
A myCat.meow;
B let myCat = new Cat();
C class Cat {
D meow() { console.log(2); }
E }
Question 3
A class Bird {
B function sing() {
C console.log("tweet");
D }
E }
Question 4
A class Duck {
B function quack() {
C console.log("quack");
D }
E }
Question 5
A class Fish {
B swim() {
C console.log("splash")
D }
E }

Answer Key

OOP – Methods
Section A: Quick Questions
Q1
B — Yes
Q2
B — No
Q3
A — Yes
Q4
A — Yes
Q5
A — Yes
Section B: Match the Pairs
Q1
bark() { console.log(this.name + " says woof"); } → Declares a method that prints the dog's name and a sound
Q2
myDog.bark(); → Calls the bark method on the myDog instance
Q3
A function declared inside a class, without 'function' → show() { ... }
Q4
Refers to the instance a method is called on → this
Q5
function bark() { console.log("woof"); } → Wrong - class methods don't use the 'function' keyword
Q6
myDog.bark; → Wrong - calling a method needs parentheses
Section C: Definitions
Q1
method — A function declared inside a class body, called on an instance using dot notation.
Section D: Fill in the Blanks
Q1
bark() { console.log(this.name + " says woof"); }
Q2
myDog.bark();
Q3
show() { console.log(this.color); }
Q4
myCar.show();
Q5
console.log(this.name + " says woof");
Section E: Spot the Error
Q1
A — Method names are case-sensitive - it should be bark(), not Bark().
Q2
A — Calling a method needs parentheses: myCat.meow().
Q3
B — Class methods skip the 'function' keyword - just write sing() {.
Q4
B — Class methods skip the 'function' keyword - just write quack() {.
Q5
C — This line is missing a semicolon, but that's not required in JS.