# AP® Computer Science A 1.10 Calling Class Methods

Source: https://lockincs.com/ap-csa/unit-1/1-10-calling-class-methods/  
Last reviewed against the College Board Course and Exam Description (CED): 2026-11-12  
CED codes: 1.10.A, 1.10.A.1, 1.10.A.2

Class methods are associated with the class, not with instances of the class, and their header has the keyword static before the method name. They are called with the class name and the dot operator, as in TempConverter.toFahrenheit(100.0). Inside the class that defines the method, the class name is optional.

## What you will learn

- 1.10.A Develop code to call class methods and determine the result of those calls.

## 1\. What a class method is

**Class methods** are associated with the class, not with instances (objects) of the class. Their header includes the keyword `static` before the method name 1.10.A.1.

Example header: `public static double toFahrenheit(double c)`. The keyword `static` tells you this is a class method. You can call it without creating any object.

## 2\. Calling a class method from another class

Class methods are typically called using the class name along with the dot operator 1.10.A.2. Here a `TempConverter` class (written by someone else) has the class method `toFahrenheit`, and a `Weather` class uses it:

```
public class Weather
{
    public static void main(String[] args)
    {
        double hot = TempConverter.toFahrenheit(100.0);
        System.out.println(hot);
        System.out.println(TempConverter.toFahrenheit(30.0));
    }
}
```

Output:

```
212.0
86.0
```

`TempConverter.toFahrenheit(100.0)` returns `212.0`. The return type is `double`, so the result is stored in a `double` variable or used in an expression, exactly as in topic 1.9.

In an unrelated class, leaving out the class name does not compile:

```
// does not compile
public class Weather2
{
    public static void main(String[] args)
    {
        System.out.println(toFahrenheit(100.0));
    }
}
```

Real view:

```
Weather2.java:6: error: cannot find symbol
        System.out.println(toFahrenheit(100.0));
                           ^
  symbol:   method toFahrenheit(double)
  location: class Weather2
1 error
```

## 3\. Calling a class method inside its own class

When the method call occurs in the defining class, the use of the class name is optional 1.10.A.2:

```
public class TempConverter
{
    public static double toFahrenheit(double c)
    {
        return c * 9 / 5 + 32;
    }

    public static void main(String[] args)
    {
        System.out.println(toFahrenheit(100.0));               // class name left out
        System.out.println(TempConverter.toFahrenheit(0.0));   // class name used
    }
}
```

Output:

```
212.0
32.0
```

Both calls work, because `main` is inside `TempConverter`.

> **Background (not tested): “static method”.** Many programmers say *static method* for what the course calls a *class method*. They mean the same thing. On the exam, expect “class method”.

## Common mix-ups

- Not true: You must create an object before calling any method. Class methods belong to the class itself. You call them with the class name, such as Math.sqrt(25.0), without creating an object.
- Not true: You can always leave out the class name. Only inside the class that defines the method. In a different class, toFahrenheit(100.0) without TempConverter. does not compile.

## In 30 seconds

- Class methods are associated with the class, not with instances of the class.
- Their header includes the keyword static before the method name.
- Call them with the class name and the dot operator: TempConverter.toFahrenheit(100.0).
- Inside the class that defines the method, the class name is optional.

## Checkpoint: 4 practice questions

### Question 1

The `TempConverter` class contains this method. Which expression, in a different class, correctly calls it?

```java
public static double toFahrenheit(double c)
```

- A. `TempConverter.toFahrenheit(30.0)`
- B. `toFahrenheit(30.0)`
- C. `TempConverter.toFahrenheit()`
- D. `TempConverter.toFahrenheit("30")`

**Answer: A.** Class methods are called with the class name and dot operator, with a double argument. B compiles only inside `TempConverter` (or a class that inherits from it). C leaves out the required argument. D passes a String, which is not compatible with the double parameter.

### Question 2

The `Geometry` class contains the following class method. Which statement, in a different class, stores the area of a circle of radius 2.0 in `a`?

```java
public static double circleArea(double r)
{
    return 3.0 * r * r;
}
```

- A. `double a = circleArea(2.0);`
- B. `double a = Geometry.circleArea(2.0);`
- C. `int a = Geometry.circleArea(2.0);`
- D. `double a = Geometry.circleArea("2.0");`

**Answer: B.** Outside the defining class, a class method is called with the class name and the dot operator, and its double result is stored in a double. A leaves out the class name, which only works inside `Geometry`. C stores a double in an int without a cast. D passes a String instead of a double.

### Question 3

Consider the following class and code segment in a different class. What is printed?

```java
public class Scores
{
    public static int bonus(int s)
    {
        return s / 10;
    }
}

// in main
int total = 47 + Scores.bonus(47);
System.out.println(total);
```

- A. `47`
- B. `51.7`
- C. `51`
- D. `4`

**Answer: C.** `Scores.bonus(47)` returns 47 / 10, which is 4 with int division, and 47 + 4 is 51. A ignores the returned value. B uses double division. D prints only the bonus, not the total.

### Question 4

Which of the following headers declares a class method?

- A. `public int getScore()`
- B. `public void static resetAll()`
- C. `public Player(String name)`
- D. `public static int maxScore()`

**Answer: D.** A class method has the keyword `static` before the method name, after the access word and before the return type. A has no `static`, so it is an instance method. B puts `static` after the return type, which does not compile. C is a constructor header.

## Questions students ask

**What is a class method in Java?**

A class method is a method associated with the class rather than with any one object. Its header includes the keyword static, as in public static double toFahrenheit(double c).

**How do you call a static method in Java?**

Use the class name, the dot operator and the method name with its arguments, such as Math.sqrt(25.0). Inside the class that defines the method you may leave out the class name.

**Is a static method the same as a class method?**

Yes. Many programmers say static method; the AP® course says class method. They mean the same thing.

---

© LockInCS, licensed CC BY-NC-ND 4.0. AP® is a trademark registered by the College Board, which is not affiliated with, and does not endorse, this website.
