1. Reference Guide

Key Topics

Term Definition Example
Class A blueprint that defines fields and methods. class Cookie { ... }
Object A specific thing made from a class using new. Cookie myCookie = new Cookie();
Instance method A method that acts on one specific object’s fields, called with the dot operator. myCookie.addChips(3);
Static (class) method A method that belongs to the blueprint, not one object. Cookie.ovenTempF();
Dot operator Syntax that tells Java which object’s data a method call should use. object.method()
NullPointerException Runtime error from calling an instance method on a null reference. Dog d = null; d.bark();
  • Instance methods need an object to run — they read or change that object’s own fields using this
  • Static methods belong to the class itself and never need an object

Instance Methods vs. Static/Class Methods

Feature Instance method Static (class) method
How you call it myCookie.addChips(2) Cookie.ovenTempF()
Has a this? Yes (this = that cookie) No — this is illegal
Can read/change per-object fields? Yes No, unless given an object as a parameter
Common uses Behavior tied to one object’s state Utilities, factory methods, class-wide info

Rules for Calling Instance Methods (AP Exam Focus)

  1. You must have an object reference — Dog.bark() is invalid unless bark is static.
  2. The object reference cannot be null — calling an instance method on a null reference throws a NullPointerException at runtime.
  3. Arguments must match parameter types exactly, or be compatible through widening conversion, in the same number and order as the method signature.
  4. A void method returns nothing — int x = d.bark(); is invalid if bark is void. A non-void method’s return value can be stored or used in an expression.
  5. Chained calls (obj.method1().method2()) evaluate left-to-right, and each method must return an appropriate object for the next call.
  6. Instance methods can call other instance methods of the same object directly, without needing this.
  7. Parameter names in the method definition don’t matter when calling — only the argument values and their order/types matter.

Spotting a Required Object

  • The call needs one specific object’s data (name, balance, position) → it’s an instance method, call it on an object
  • The call is a utility that doesn’t depend on any one object’s state → it’s likely static, call it on the class name
  • The reference variable might never have been assigned an object → check for null before calling an instance method on it

2. LxD Cycle Process

Empathize: I noticed students, when shown a class for the first time, often try to call its methods directly on the class name (Dog.bark()) the way they call Math.sqrt(). They have not yet separated “this belongs to the blueprint” (static) from “this belongs to one specific cookie” (instance).

Define:

  • POV: CSA students need a reliable rule for when a method call requires an object because the AP Exam repeatedly tests code that looks almost identical between the static and instance forms.
  • Learning Goal: Students will correctly call instance methods using the dot operator on an object reference, distinguish instance methods from static/class methods, and predict when a call will throw a NullPointerException or fail to compile.

Ideate:

  • HMW Question: How might we give students one simple test they can apply to any method call to decide “do I need an object first?”
  • Activity: A cookie-recipe analogy — the recipe (class) is not a cookie, so Cookie.getOvenTemperature() (blueprint-level, static) and myCookie.addChips(3) (specific-cookie-level, instance) look almost the same but mean very different things.

Prototype & Test: In a trial run using only the MC Hacks, students who got Question 1 wrong all picked the option that called deposit/getBalance directly on the class name. I added the cookie analogy and an explicit Reference Guide comparison table before showing any multiple-choice questions, which resolved the confusion in a re-test.


3. College Board Requirements

AP CSA Unit 1, Topic 1.14 Calling Instance Methods. Quoted from the course and exam description (College Board, 2025, p. 48):

  • “Instance methods are called on objects of the class. The dot operator is used along with the object name to call instance methods.”
  • “A method call on a null reference will result in a NullPointerException.”

The dot-operator syntax this lesson teaches is also formally defined by the Java Language Specification’s rules for method invocation expressions (Gosling et al., 2023, §15.12); see References.


4. Lesson Plan

Learning Objective: By the end of this lesson, you will be able to call instance methods on an object using the dot operator, determine the result of an instance method call, and distinguish an instance method from a static/class method.

Success Criteria: You can look at a code segment calling a method and say whether it compiles, whether it needs an object first, and — if it does — whether a null reference would cause a runtime exception.

Tech Talk & Introduction (5 minutes)

  • Class = blueprint. A Cookie recipe says what ingredients exist and what steps to follow.
  • Object = a thing made from the blueprint. Each cookie baked with new Cookie(...) is its own entity with its own chocolate chips.
  • Method = an action. A static/class method belongs to the blueprint, not one cookie (Cookie.getOvenTemperature() is true for all cookies). An instance method needs one particular cookie to run, because it reads or changes that cookie’s own fields using this — you call it on an object, like myCookie.addChips(3);.

Why do we do this? Every instance method call in Java is really “send this message to this specific object.” The dot operator (object.method()) is what tells Java which object’s data the method should read or change.

sequenceDiagram
    participant Main
    participant c as Counter

    Main->>Counter: new Counter()
    activate c
    Main->>c: add(5)
    c-->>Main: (void)
    Main->>c: getCount()
    c-->>Main: 5
    deactivate c

5. Code Examples

A. Simple: Syntax of Calling an Instance Method

// Suppose we have a class:
public class Dog {
    private String name;
    public Dog(String name) {
        this.name = name;
    }
    public void bark() {
        System.out.println(name + " says: Woof!");
    }
}

// To use it:
Dog d = new Dog("Fido");  // create an instance
d.bark();                 // call the instance method on d
Fido says: Woof!

d.bark(); invokes the bark method on the object d. Inside bark, name refers to d’s own name.

B. Intermediate: Passing Arguments to an Instance Method

public class Counter {
    private int count;
    public void add(int x) {
        count += x;
    }
    public int getCount() {
        return count;
    }
}

// Use it:
Counter c = new Counter();
c.add(5);
int val = c.getCount();  // returns 5

c.add(5); calls method add on c with argument 5. c.getCount(); calls a non-void method that returns an int.

C. Complex: One Instance Method Calling Another

public class Turtle {
    private int x, y;
    public void forward(int distance) {
        // move the turtle forward by distance
    }
    public void turnLeft(int degrees) {
        // rotate turtle direction
    }
    public void drawHouse() {
        // uses forward and turnLeft to draw a house
        forward(50);
        turnLeft(90);
        forward(50);
        // etc.
    }
}
Turtle t = new Turtle();
t.drawHouse();   // high-level call, internally calls forward, turnLeft, etc.

Here, drawHouse is an instance method that, when invoked on t, calls other instance methods (forward, turnLeft) on that same object (implicitly this.forward(...), etc.).

D. Bonus: A Class With Two Instance Methods Working Together

// Define the Joke class
class Joke {
    private String setup;
    private String punchline;

    public Joke(String setup, String punchline) {
        this.setup = setup;
        this.punchline = punchline;
    }

    public void tellJoke() {
        System.out.println(setup);
        System.out.println(punchline);
    }
}

// Create and run a joke
Joke myJoke = new Joke("Why don't programmers like nature?",
                       "Because it has too many bugs!");

myJoke.tellJoke();

6. Hacks & Practice Tasks

Submission Safety Rules (Read First)

[!IMPORTANT] To avoid grading errors, follow these rules exactly:

  • Every method you add must be called on an object, never on the class name, unless it is intentionally static.
  • Run every code cell and leave the output visible before submitting.
  • For each MC Hack answer, write one sentence justifying your choice using a rule from the Reference Guide.

Popcorn Hack #1

[!TIP] Add the field first, then write the method, then create the object — in that order.

  • Add another property to the dog class for breed.
  • Add another method to the dog class that prints “My dog name is a breed!”
  • Create a new object of this class and call the method.
public class Dog {

    // ADD CODE HERE
}

// To use it:
// ADD CODE HERE

Popcorn Hack #2

[!TIP] Each new method follows the same pattern as add: read count, combine it with the parameter, store the result back in count.

  • Add on to the previous counter class and add three more methods for subtraction, multiplication, and division.
  • Call all five methods outside of the class.
public class Counter {
    private int count;
    
    // ADD CODE HERE
}

// Use it:
// ADD CODE HERE

Homework Hack: MC Practice

For each question, pick an answer and write one sentence citing which Reference Guide rule justifies it.

Question 1

Consider the following class:

public class BankAccount {
    private double balance;
    
    public BankAccount(double initialBalance) {
        balance = initialBalance;
    }
    
    public void deposit(double amount) {
        balance += amount;
    }
    
    public double getBalance() {
        return balance;
    }
}

Which of the following code segments will compile without error:

A)

BankAccount.deposit(50.0);
double total = BankAccount.getBalance();

B)

BankAccount account = new BankAccount(100.0);
account.deposit(50.0);
double total = account.getBalance();

C)

BankAccount account = new BankAccount(100.0);
double total = account.deposit(50.0);

D)

BankAccount account;
account.deposit(50.0);
double total = account.getBalance();

E)

double total = getBalance();
BankAccount account = new BankAccount(total);

Question 2

What is printed as a result of executing the following code?

public class Rectangle {
    private int length;
    private int width;
    
    public Rectangle(int l, int w) {
        length = l;
        width = w;
    }
    
    public int getArea() {
        return length * width;
    }
    
    public void scale(int factor) {
        length *= factor;
        width *= factor;
    }
}

Rectangle rect = new Rectangle(3, 4);
rect.scale(2);
System.out.println(rect.getArea());

A) 12

B) 24

C) 48

D) 96

E) Nothing is printed; the code does not compile

Question 3

Which of the following best describes when a NullPointerException will occur when calling an instance method?

A) When the method is declared as void

B) When the method is called on a reference variable that has not been initialized to an object

C) When the method’s parameters do not match the arguments provided

D) When the method is called from outside the class

E) When the method attempts to return a value but is declared as void

Question 4

Which of the following code segments will NOT compile?

public class Temperature {
    private double celsius;
    
    public Temperature(double c) {
        celsius = c;
    }
    
    public double getFahrenheit() {
        return celsius * 9.0 / 5.0 + 32;
    }
    
    public void setCelsius(double c) {
        celsius = c;
    }
}

A)

Temperature temp = new Temperature(0);
System.out.println(temp.getFahrenheit());

B)

Temperature temp = new Temperature(100);
temp.setCelsius(25);

C)

Temperature temp = new Temperature(20);
double f = temp.getFahrenheit();

D)

Temperature temp = new Temperature(15);
int result = temp.setCelsius(30);

E)

Temperature temp = new Temperature(0);
temp.setCelsius(100);
double f = temp.getFahrenheit();

Question 5

Consider the following class:

public class Book {
    private String title;
    private int pages;
    
    public Book(String t, int p) {
        title = t;
        pages = p;
    }
    
    public String getTitle() {
        return title;
    }
    
    public int getPages() {
        return pages;
    }
    
    public void addPages(int additional) {
        pages += additional;
    }
}

Assume that the following code segment appears in a class other than Book:

Book novel = new Book("Java Basics", 200);
novel.addPages(50);
/* missing code */

Which of the following can replace /* missing code */ so that the value 250 is printed?

A) System.out.println(pages);

B) System.out.println(novel.pages);

C) System.out.println(Book.getPages());

D) System.out.println(novel.getPages());

E) System.out.println(getPages());

Grading Plan (1 Point Total)

Classroom Rubric

  • 0.2 points: Popcorn completion Both Popcorn Hacks add correct instance methods, called on an object (never on the class name), and run successfully.

  • 0.8 points: Homework completion

    • 0.6 Correct answers: At least 4 of 5 MC Hack questions answered correctly.
    • 0.2 Justification: Each answer cites a specific rule from the Reference Guide (e.g., “D fails because account was never assigned an object”).

Quick Validation Checklist

  • Present: both Popcorn Hacks run with visible output
  • Present: a one-sentence justification for every MC answer
  • Absent: any method called directly on a class name where an object was required

7. Lesson Revisions

Revision Made: I merged both overlapping rule lists into one seven-rule Reference Guide list, removing duplicated points, so there is a single authoritative rule list students reference during the MC Hacks. I also added a requirement that each MC Hack answer cite a specific Reference Guide rule, which the Grading Plan now scores directly.


8. Feedback Evidence

Feedback Received: The original lesson had two separate, overlapping rule lists — “Key points & common errors” (4 items) and “Important Rules to Keep in Mind (AP Test-Specific)” (7 items) — that repeated several of the same rules in different words, which reviewers said made it unclear which list to actually study. Reviewers also noted the five MC Hacks originally had no required justification, so students could guess-and-check.


9. References

College Board. (2025). AP Computer Science A: Course and exam description. https://apcentral.collegeboard.org/media/pdf/ap-computer-science-a-course-and-exam-description.pdf

Gosling, J., Joy, B., Steele, G., Bracha, G., & Buckley, A. (2023). The Java language specification: Java SE 21 edition (§15.12, Method Invocation Expressions). Oracle America. https://docs.oracle.com/javase/specs/jls/se21/html/jls-15.html

past lesson

Submit Assignment

Click to upload or drag and drop
PDF, ZIP, images, documents, or Jupyter notebooks (.ipynb) (Max 10MB per file)

Need to update a submission later? Open the submissions dashboard.