---
title: "AP CSA 3.7: Static Variables and Methods"
description: "Review AP Computer Science A Topic 3.7, including static variables, static methods, class variables, class methods, the static keyword, shared object counters, final constants, and what static methods can and cannot access."
canonical: "https://fiveable.me/ap-comp-sci-a/unit-3/static-variables-and-methods/study-guide/zzhHVbXBRCZQ7ng3EeWX"
type: "study-guide"
subject: "AP Computer Science A"
unit: "Unit 3 – Class Creation"
lastUpdated: "2026-06-07"
---

# AP CSA 3.7: Static Variables and Methods

## Summary

Review AP Computer Science A Topic 3.7, including static variables, static methods, class variables, class methods, the static keyword, shared object counters, final constants, and what static methods can and cannot access.

## Guide

## TLDR
Static variables and methods belong to the class itself, not to any single [object](/ap-comp-sci-a/key-terms/object "fv-autolink"). A static (class) variable is shared by every object of the class because there is only one copy, and a static (class) method runs without needing a specific object. In [AP Computer Science A](/ap-comp-sci-a "fv-autolink"), you mainly need to declare class variables with `static`, access them with the class name, and know that class methods cannot touch instance variables or call instance methods unless you pass them an object.

## Why This Matters for the AP Computer Science A Exam

Class variables and methods show up when a problem needs data or behavior that is shared across all objects, like a counter that tracks how many objects have been created. On the multiple-choice section, you may need to trace code and predict output when several objects share one static variable, or spot why a [class method](/ap-comp-sci-a/unit-3/this-keyword/study-guide/Zste3M7m756uzwR0zCQK "fv-autolink") cannot reach an instance variable. In free-response code writing, a class design problem may ask you to keep a shared count or define a behavior that works at the class level, so you need to declare and use `static` members correctly.

Knowing the line between class level and [instance](/ap-comp-sci-a/unit-1/objects-instances-of-classes/study-guide/EcpFHGcIKu6385hMohLe "fv-autolink") level also helps you avoid [compile](/ap-comp-sci-a/key-terms/compile "fv-autolink") errors, which the exam tests when it asks why a code segment will not work and how to fix it.

## Key Takeaways

- A class variable uses the `static` keyword and is shared by every object of the class, so all objects see and change the same single copy.
- [Public](/ap-comp-sci-a/key-terms/public "fv-autolink") class variables are accessed from outside the class with the class name and the [dot operator](/ap-comp-sci-a/key-terms/dot-operator "fv-autolink"), like `ClassName.variable`, because they belong to the class, not to an object.
- A class method ([static method](/ap-comp-sci-a/key-terms/static-method "fv-autolink")) can read and change class variables and call other class methods.
- A class method cannot access instance variables or call instance methods unless it receives an object of the class as a [parameter](/ap-comp-sci-a/key-terms/parameter "fv-autolink").
- Declaring a variable `final` means its value cannot be changed after it is set, which is how you make a constant.

## Core Concepts

### Class Level vs Instance Level

Every value in a class lives at one of two levels. An instance variable belongs to each object, so each object gets its own copy. A class variable belongs to the class itself, so there is only one copy shared by all objects.

You mark a class variable with the `static` keyword before its type. The moment you add `static`, you are saying "this belongs to the class, not to any one object."

```java
public class Student {
    // Instance variable - each Student object has its own name
    private String name;

    // Class variable - one shared copy for all Student objects
    private static int totalStudents = 0;

    public Student(String studentName) {
        this.name = studentName;
        totalStudents++;   // every new Student updates the shared count
    }

    public String getName() {
        return name;
    }

    // Class method - reads the shared class variable
    public static int getTotalStudents() {
        return totalStudents;
    }
}
```

Each `Student` keeps a separate `name`, but they all share one `totalStudents`. When any [constructor](/ap-comp-sci-a/unit-1/creating-and-storing-objects/study-guide/rUOTKl6Ih5noXJ0GtxJF "fv-autolink") runs `totalStudents++`, the change is visible to every object.

### Accessing Public Class Variables and Methods

Because class variables and class methods belong to the class, you reach public ones with the class name and the dot operator. You do not need an object.

```java
Student alice = new Student("Alice");
Student bob = new Student("Bob");

// Class method called on the class name, not an object
System.out.println(Student.getTotalStudents());  // 2
```

Both objects increased the same shared counter, so the class reports 2. This is the behavior you trace on multiple-choice questions: one static variable, many objects, a single shared value.

### What Class Methods Can and Cannot Do

A class method runs at the class level, so it does not automatically have an object to work with. That leads to two rules you need for the exam:

- A class method **can** access or change class variables and call other class methods.
- A class method **cannot** access instance variables or call instance methods unless it is passed an instance of the class as a parameter.

```java
public class Counter {
    private int count;                  // instance variable
    private static int objectsMade = 0; // class variable

    public Counter() {
        count = 0;
        objectsMade++;
    }

    // Class method that gets an object passed in, so it CAN use instance data
    public static int readCount(Counter c) {
        return c.count;   // allowed because c is an instance parameter
    }

    // Class method using only class-level data
    public static int howManyMade() {
        return objectsMade;
    }
}
```

`howManyMade` works at the class level with no object. `readCount` can touch the instance variable `count` only because it receives a `Counter` object named `c`. Without that parameter, a class method has no instance to reach into.

### Constants with final

Declaring a variable `final` means its value cannot be modified after it is assigned. Combining `static` and `final` is the standard way to make a shared constant that every object can use but no one can change.

```java
public class Circle {
    public static final double PI = 3.14159;

    private double radius;

    public Circle(double r) {
        radius = r;
    }

    public double area() {
        return PI * radius * radius;
    }
}
```

Here `PI` is one shared value for the whole class, and `final` stops any code from reassigning it. You can read it from outside with `Circle.PI`.

## How to Use This on the AP Computer Science A Exam

### Code Tracing

When you see one `static` variable and several objects, track a single shared value, not one per object. Each time any object changes the class variable, the new value carries over to the next line for every object. A common multiple-choice setup creates a few objects, has each constructor increment a static counter, then prints the counter.

### Free Response

In a class design problem, read the specification for anything shared across all objects, such as a running total or count of objects created. Declare that as a `static` variable and [update](/ap-comp-sci-a/unit-2/for-loops/study-guide/DJuLxKz6SiSAX2cEVmCt "fv-autolink") it in the constructor or methods. Keep regular per-object data as instance variables. Access public class members with the class name and the dot operator when you call them from outside the class.

### Common Trap

If a class method tries to use an instance variable or call an [instance method](/ap-comp-sci-a/key-terms/instance-method "fv-autolink") directly, the code will not compile. On "why will this not compile" questions, check whether a static method is reaching for instance data without being given an object. The fix is to pass an instance of the class as a parameter, then use that parameter to reach the instance data.

## Common Misconceptions

- **"Each object gets its own copy of a static variable."** No. There is exactly one copy of a class variable, shared by every object. Changing it through any object changes it for all.
- **"You need to create an object to call a static method."** You call public class methods with the class name and dot operator, like `ClassName.method()`. No object required.
- **"A static method can use instance variables like any other method."** It cannot, unless it receives an object as a parameter. Class methods have no automatic object to work with.
- **"final and static mean the same thing."** They are different. `static` means the variable belongs to the class and is shared. `final` means the value cannot be changed after assignment. A constant often uses both together.
- **"Calling a static variable through an object is the intended way to use it."** Since the variable belongs to the class, access it through the class name to make the class-level meaning clear.

## Related AP Computer Science A Guides

- [3.8 Scope and Access](/ap-comp-sci-a/unit-3/scope-and-access/study-guide/56FUK4RSofr7slzwm6xm)
- [3.3 Anatomy of a Class](/ap-comp-sci-a/unit-3/anatomy-of-a-class/study-guide/DcGY5KOyK98H9Fn2w8jh)
- [3.9 This Keyword](/ap-comp-sci-a/unit-3/this-keyword/study-guide/Zste3M7m756uzwR0zCQK)
- [3.5 Writing Methods](/ap-comp-sci-a/unit-3/writing-methods/study-guide/rtuMpRFmidkpYTzvDndS)
- [3.4 Constructors](/ap-comp-sci-a/unit-3/constructors/study-guide/3Ez6zzak2wRwMrTj2ZQk)
- [3.1 Abstraction and Program Design](/ap-comp-sci-a/unit-3/abstraction-and-program-design/study-guide/o9VgVeIpKRYZ7N7rXfUz)

## Vocabulary

- **class methods**: Methods that are associated with a class rather than with instances of the class, and include the static keyword in their header.
- **class variable**: Variables that belong to the class itself rather than individual objects and can be accessed or modified by accessor and mutator methods.
- **dot operator**: The symbol (.) used in Java to access instance methods and properties of an object.
- **final keyword**: A Java keyword that, when applied to a variable, prevents its value from being modified after initialization.
- **instance methods**: Methods that belong to an object and are called on specific instances of a class using the dot operator.
- **instance variable**: A variable that belongs to an object and can be accessed throughout the class, as opposed to a local variable that is limited to a specific block of code.
- **parameter**: A variable declared in the header of a method or constructor that receives values passed to the method when it is called.
- **public access modifier**: A keyword that allows class variables to be accessed outside of the class using the class name and dot operator.
- **static keyword**: A Java keyword used to designate that a variable belongs to the class rather than to individual objects of the class.

## FAQs

### What does static mean in AP Computer Science A?

Static means the variable or method belongs to the class, not to one object. There is one shared class-level member instead of a separate copy for each instance.

### What is a static variable in Java?

A static variable is a class variable shared by all objects of the class. It is declared with the static keyword before the variable type.

### What is a static method in Java?

A static method is a class method that can be called with the class name and does not require an object. It can access class variables and call other class methods.

### Can a static method access instance variables?

Not directly. A static method has no automatic object, so it can access instance variables only if an object is passed as a parameter.

### How do you call a public static method?

Call it with the class name and dot operator, such as ClassName.methodName(). That makes clear the method belongs to the class.

### What is the difference between static and final?

Static means a member belongs to the class and is shared. Final means a variable cannot be reassigned after it is set. Constants often use both static and final.

## Structured Data

```json
{"@context":"https://schema.org","@type":"FAQPage","inLanguage":"en","mainEntity":[{"@type":"Question","@id":"https://fiveable.me/ap-comp-sci-a/unit-3/static-variables-and-methods/study-guide/zzhHVbXBRCZQ7ng3EeWX#what-does-static-mean-in-ap-computer-science-a","name":"What does static mean in AP Computer Science A?","acceptedAnswer":{"@type":"Answer","text":"Static means the variable or method belongs to the class, not to one object. There is one shared class-level member instead of a separate copy for each instance."}},{"@type":"Question","@id":"https://fiveable.me/ap-comp-sci-a/unit-3/static-variables-and-methods/study-guide/zzhHVbXBRCZQ7ng3EeWX#what-is-a-static-variable-in-java","name":"What is a static variable in Java?","acceptedAnswer":{"@type":"Answer","text":"A static variable is a class variable shared by all objects of the class. It is declared with the static keyword before the variable type."}},{"@type":"Question","@id":"https://fiveable.me/ap-comp-sci-a/unit-3/static-variables-and-methods/study-guide/zzhHVbXBRCZQ7ng3EeWX#what-is-a-static-method-in-java","name":"What is a static method in Java?","acceptedAnswer":{"@type":"Answer","text":"A static method is a class method that can be called with the class name and does not require an object. It can access class variables and call other class methods."}},{"@type":"Question","@id":"https://fiveable.me/ap-comp-sci-a/unit-3/static-variables-and-methods/study-guide/zzhHVbXBRCZQ7ng3EeWX#can-a-static-method-access-instance-variables","name":"Can a static method access instance variables?","acceptedAnswer":{"@type":"Answer","text":"Not directly. A static method has no automatic object, so it can access instance variables only if an object is passed as a parameter."}},{"@type":"Question","@id":"https://fiveable.me/ap-comp-sci-a/unit-3/static-variables-and-methods/study-guide/zzhHVbXBRCZQ7ng3EeWX#how-do-you-call-a-public-static-method","name":"How do you call a public static method?","acceptedAnswer":{"@type":"Answer","text":"Call it with the class name and dot operator, such as ClassName.methodName(). That makes clear the method belongs to the class."}},{"@type":"Question","@id":"https://fiveable.me/ap-comp-sci-a/unit-3/static-variables-and-methods/study-guide/zzhHVbXBRCZQ7ng3EeWX#what-is-the-difference-between-static-and-final","name":"What is the difference between static and final?","acceptedAnswer":{"@type":"Answer","text":"Static means a member belongs to the class and is shared. Final means a variable cannot be reassigned after it is set. Constants often use both static and final."}}]}
```
