1.10 Calling Class Methods
Call static methods on class names and trace nested method calls step-by-step.
1. Reference Guide
A class method belongs to the class, not to any one object. Knowing when a call needs an object (and when it does not) is the key to reading and writing Java classes.
Key Topics
| Term | Definition | Example |
|---|---|---|
| Class method | A method associated with the class, not a specific object. | Calculator.square(5) |
static |
The keyword that makes a method a class method. | public static int square(int n) |
| Instance method | A method that belongs to an object and needs one to run. | p.printStatus() |
| Instance variable | A variable each object has its own copy of. | String name; |
| Static context | Code inside a static method, where there is no current object. |
public static void main(...) |
| Return value | The value a non-void method gives back to the caller. |
return number * number; |
| Nested call | A method call used as an argument to another call. | add(square(2), square(3)) |
Static vs. Instance
| Type | Belongs to | Typical call |
|---|---|---|
| Class / static method | The class | ClassName.method() |
| Instance method | An object | objectName.method() |
Which Call Form?
| Situation | Call form |
|---|---|
| Static method, called from another class | ClassName.method() |
| Static method, called inside its own class | method() or ClassName.method() |
| Instance method | object.method() (an object is required) |
Static method through an object (r.beep()) |
Compiles, but ClassName.method() is clearer |
Common Errors
non-static method ... cannot be referenced from a static context: you called an instance method as if it were static.non-static variable ... cannot be referenced from a static context: a static method tried to use an instance variable directly.- Nested calls run from the inside out: the innermost call finishes first.
2. LxD Cycle Process
Empathize: Students may read static as meaning “constant” or “global,” assume every method call needs an object, or call an instance method with a class name. Because Java permits a static method to be called through an object reference, code can compile while reinforcing the mistaken idea that the method belongs to that object. Students may also expect a class method to access instance fields without selecting an instance.
Define:
- POV: Students learning class methods need to connect
staticwith the absence of a current object, because call syntax alone can hide whether a particular instance is involved. - Learning Issue: Students need to distinguish “valid Java” from the clearest call form and explain why
ClassName.method()communicates class ownership. - Learning Goal: Students will identify class methods, call them correctly with and without the class name, explain why a static method cannot use an instance variable directly, and trace nested method calls to find their result.
Ideate:
- HMW Question: How might we make the presence or absence of a current object visible during a method call?
- HMW Question: How might we help students diagnose a static-context error from the data the method tries to access?
- Activity: Sort call cards into class-method and instance-method columns, justify the receiver for each call, and repair one call that produces a static-context compiler error.
Prototype:
- A reference guide, runnable Java examples, a call-predictor popcorn hack, an MCQ knowledge check, and a scaffolded repair-the-code rubric.
- Students revise their predictions after seeing runner output and compiler errors.
- Excellence means explaining why a call is valid or invalid, not only fixing it.
Test:
- Give a partner one class with a static method, an instance method, and an instance field.
- Have the partner predict which calls compile and explain each receiver.
- Revise the example if the explanation relies only on memorized punctuation.
- On submission, collect evidence from runner output, MCQ results, AI grading, and student explanations.
- After teaching, grading, and analysis, come back and revise the lesson to complete the teaching cycle for continuous improvement.
3. College Board Requirements
AP CSA Unit 1, Topic 1.10 Calling Class Methods. From the course and exam description (College Board, 2025, p. 43): class methods are “associated with the class, not instances.”
This lesson covers these Topic 1.10 ideas (paraphrased; check exact wording and numbering in the CED):
- Class methods are associated with the class rather than an object, and their headers include the
statickeyword. - A class method is called with the class name and a dot, as in
ClassName.methodName(). Inside the class that defines it, the class name may be left out. - A class method cannot directly access or change an instance variable, because no specific object is attached to the call. The Java Language Specification describes a static method as invoked without reference to a particular object (Gosling et al., 2025, §8.4.3.2).
- Instance methods need an object, so they are called on an object reference.
- Calls can be traced: a non-
voidmethod returns a value that can be printed, stored, or used in an expression, including as an argument to another call.
4. Lesson Plan
Learning Objective: Identify class methods, call them correctly, and determine the result of calls to class methods.
Success Criteria: Given a method and a call, you can explain whether it is a class or instance method and whether the call is valid.
Tech Talk (5 minutes)
A class method is associated with the class rather than a particular object. In Java, class methods use the static keyword.
Code Runner Challenge
Run it, then uncomment the bad call and read the compiler error
View IPYNB Source
public static void printMessage(String message) {
System.out.println(message);
}
Because printMessage is static, it can be called using the class name, with no Printer object:
Code Runner Challenge
Run it, then add a third call to square with a different number
View IPYNB Source
Printer.printMessage("Hello!");
| Type | Belongs to | Typical call |
|---|---|---|
| Class / static method | Class | ClassName.method() |
| Instance method | Object | objectName.method() |
printMessage() is static, so it belongs to Printer. printStatus() is an instance method, so Java needs a particular Printer object.
If you see an error like “non-static method … cannot be referenced from a static context,” check whether you are calling an instance method as if it were static.
Code Runner Challenge
Run it, then uncomment the bad call and read the compiler error.
Code Runner Challenge
Run it, trace each line by hand first, then change a number and predict the output
View IPYNB Source
// CODE_RUNNER: Run it, then uncomment the bad call and read the compiler error
public class Printer {
public static void printMessage(String message) {
System.out.println(message);
}
public void printStatus() {
System.out.println("Printer is ready.");
}
public static void main(String[] args) {
Printer.printMessage("Hello!"); // works: static, called on the class
Printer p = new Printer();
p.printStatus(); // works: instance method, called on an object
// Printer.printStatus(); // ERROR: instance method needs an object
}
}
Printer.main(null);
5. Code Examples
A. Calling a static method inside its own class
The Calculator class calls its own static method two ways. When the call is inside the class that defines the method, the class name is optional.
Code Runner Challenge
Run it, then uncomment the static printName and read the compiler error
View IPYNB Source
Calculator.square(5); // with the class name
square(5); // without it (only inside Calculator)
Terminology: Both calls produce 25. From a different class, you must use Calculator.square(5).
Code Runner Challenge
Replace every "?" with WORKS or ERROR, then run it and compare
View IPYNB Source
// CODE_RUNNER: Run it, then add a third call to square with a different number
public class Calculator {
public static int square(int number) {
return number * number;
}
public static void main(String[] args) {
System.out.println(square(5)); // 25, class name omitted
System.out.println(Calculator.square(5)); // 25, class name included
}
}
Calculator.main(null);
B. Nested calls and tracing
The NestedCalls class puts method calls inside other method calls. Java runs them from the inside out, and each call is replaced by its return value.
Trace of add(square(2), square(3)):
square(2)returns 4square(3)returns 9add(4, 9)returns 13
Terminology: Math.max is a real class method from Java’s Math class, so you call it as Math.max(a, b) with no Math object.
Code Runner Challenge
Write your corrected calls in main, fill in your explanation, then run it
View IPYNB Source
// CODE_RUNNER: Run it, trace each line by hand first, then change a number and predict the output
public class NestedCalls {
public static int square(int n) { return n * n; }
public static int add(int a, int b) { return a + b; }
public static void main(String[] args) {
System.out.println(square(3)); // 9
System.out.println(add(square(2), square(3))); // 4 + 9 = 13
System.out.println(square(add(1, 2))); // square(3) = 9
System.out.println(Math.max(square(2), 3)); // max(4, 3) = 4
}
}
NestedCalls.main(null);
C. Static methods and instance variables
A static method cannot directly use an instance variable. The variable name belongs to an individual Student, and a static method is not connected to one specific student.
public static void printName() {
System.out.println(name); // ERROR: which student's name?
}
Terminology: An instance method can use name, because it runs on a specific object.
// CODE_RUNNER: Run it, then uncomment the static printName and read the compiler error
public class Student {
String name;
public Student(String name) {
this.name = name;
}
// ERROR if uncommented: a static method has no specific student
// public static void printName() { System.out.println(name); }
public void printName() { // instance method: uses this student's name
System.out.println(name);
}
public static void welcome() { // static method: uses no instance data
System.out.println("Welcome to class!");
}
public static void main(String[] args) {
Student.welcome();
Student s = new Student("Ari");
s.printName();
}
}
Student.main(null);
6. Hacks & Practice Tasks
Prepare your submission IPYNB
- Create a new notebook in your portfolio homework area:
_notebooks/homework. - Add one raw cell at the top with the frontmatter.
- Add code cells for the Popcorn Hack and the Homework Hack. Make sure every cell runs with visible output.
- Submit the link to your published page at the bottom of this page, and paste this in the description box:
Lesson: CSA 1.10 Calling Class Methods
MCQ 1.10: <paste your score line, such as 4/5 | answers: B,C,A,D,C>
Popcorn: four call predictions made, cell runs and prints
Homework: rules() called as a class method (yes/no)
Homework: Game object created and showPlayer() called on it (yes/no)
Homework: program compiles and runs (yes/no)
Homework: explanation of the original error = <your one or two sentences>
Submission Safety Rules (Read First)
- One class per cell, ending with
ClassName.main(null);. - Run each cell and leave the output showing.
- Write your own answers, not the sample code from the lesson.
- Include your MCQ score.
- Use
##headings or smaller.
Popcorn Hack (In-Class)
2-minute challenge: decide whether each call works.
- Write WORKS or ERROR for each of the four calls.
- Run the cell and compare your predictions with the output.
- Uncomment the bad call and read the compiler message.
- For the call that works two ways, note which form is clearer.
Replace every "?" with your own answer.
// CODE_RUNNER: Replace every "?" with WORKS or ERROR, then run it and compare
public class Robot {
String name;
public Robot(String name) {
this.name = name;
}
public void introduce() {
System.out.println("I am " + name);
}
public static void beep() {
System.out.println("Beep!");
}
// Predict BEFORE running (Robot r = new Robot("R2"))
static String call1 = "?"; // Robot.beep();
static String call2 = "?"; // r.beep();
static String call3 = "?"; // Robot.introduce();
static String call4 = "?"; // r.introduce();
public static void main(String[] args) {
Robot r = new Robot("R2");
System.out.println("Predictions: " + call1 + ", " + call2 + ", " + call3 + ", " + call4);
Robot.beep();
r.beep();
// Robot.introduce(); // uncomment to see the compiler error
r.introduce();
}
}
Robot.main(null);
MCQ Check
5 questions, one at a time. Answer, check, then go to the next one. At the end, copy your score line (for example 4/5 | answers: B,C,A,D,C) into your submission notes.
Question 1 of 5
Which keyword makes a method a class method?
- A.
final - B.
static - C.
void - D.
public
Check answer
**B.** `static` in the method header marks it as a class method. `public` controls access, `void` is a return type, and `final` prevents change.Question 2 of 5
The method public static int square(int n) is in class Calculator. Which call works from a different class?
- A.
Calculator().square(5) - B.
square(5) - C.
Calculator.square(5) - D.
Calculator->square(5)
Check answer
**C.** From another class, call a static method with the class name and a dot. Leaving the class name off (B) only works inside `Calculator`.Question 3 of 5
Printer has a static method printMessage(String) and an instance method printStatus(). Which call does not work?
- A.
Printer.printStatus(); - B.
new Printer().printStatus(); - C.
Printer.printMessage("Hi"); - D.
Printer p = new Printer(); p.printMessage("Hi");
Check answer
**A.** `printStatus()` is an instance method, so it needs an object. D compiles because Java allows static calls through an object, but C is the clearer form.Question 4 of 5
Why does this code fail to compile?
public class Student {
String name;
public static void printName() {
System.out.println(name);
}
}
- A.
nameis never initialized - B.
printlncannot be used in a static method - C.
printNamemust return a value - D. A static method has no specific object, so it cannot directly use the instance variable
name
Check answer
**D.** `name` belongs to an individual `Student`. A static method is not attached to any one student.Question 5 of 5
public static int square(int n) { return n * n; }
// in main:
System.out.println(square(square(2)));
What prints?
- A. 4
- B. 8
- C. 16
- D. 25
Check answer
**C.** The inner call runs first: `square(2)` is 4. Then `square(4)` is 16.Homework Hack
Task: The original program below does not compile. Fix it, then explain the error in one or two sentences.
public static void main(String[] args) {
Game.rules();
Game.showPlayer(); // ERROR
}
Your corrected main should:
- Call
rules()as a class method. - Create a
Gameobject. - Call
showPlayer()on that object. - Run without errors.
// CODE_RUNNER: Write your corrected calls in main, fill in your explanation, then run it
public class Game {
String player;
public Game(String player) {
this.player = player;
}
public void showPlayer() {
System.out.println("Player: " + player);
}
public static void rules() {
System.out.println("Each player gets one turn.");
}
public static void main(String[] args) {
// ORIGINAL (does not compile):
// Game.rules();
// Game.showPlayer();
// TODO: your corrected calls go here
// My explanation of the original error: ?
}
}
Game.main(null);
Grading Plan (1 Point Total)
| Part | Points | What earns the points |
|---|---|---|
| Popcorn | 0.2 | Four WORKS/ERROR predictions made and the cell runs. |
| MCQ | 0.2 | 4 or 5 correct. 0.15 for 3, 0.1 if every question was answered. |
| Homework: class method call | 0.1 | rules() is called as a class method. |
| Homework: object call | 0.2 | A Game object is created and showPlayer() is called on it. |
| Homework: compiles and runs | 0.15 | The corrected program compiles and prints output. |
| Homework: explanation | 0.15 | Explanation says showPlayer() is an instance method that needs an object, so the class-name call was invalid. |
| Total | 1.0 |
Quick Validation Checklist
- Each cell ends with
ClassName.main(null);and shows output. - MCQ score in the notes.
rules()is called as a static method.showPlayer()is called on aGameobject.- The program compiles and runs.
- One- or two-sentence explanation of why
Game.showPlayer()was invalid.
7. Lesson Revisions
Revision Made: Made more mcq questions to practice collegeboard testing requirements and also put in code runners for more interactive element, moved the key concepts to front of the lesson
8. Feedback Evidence
Feedback Received: Tested with group members and discovered that many just wanted to practice mcq and have a quick thing they could read in the beginning
9. References
College Board. (2025). AP Computer Science A course and exam description [Effective fall 2025]. https://apcentral.collegeboard.org/media/pdf/ap-computer-science-a-course-and-exam-description-effective-fall-2025.pdf
Gosling, J., Joy, B., Steele, G., Bracha, G., Buckley, A., Smith, D., & Bierman, G. (2025). The Java language specification: Java SE 25 edition (Sec. 8.4.3.2). Oracle. https://docs.oracle.com/javase/specs/jls/se25/html/jls-8.html#jls-8.4.3.2
Submit Assignment
Need to update a submission later? Open the submissions dashboard.