---
title: "Private Instance Variable — AP CSA Definition & Exam Guide"
description: "A private instance variable is a class field only accessible inside its own class. It's the heart of encapsulation and required on the AP CSA class design FRQ."
canonical: "https://fiveable.me/ap-comp-sci-a/key-terms/private-instance-variable"
type: "key-term"
subject: "AP Computer Science A"
---

# Private Instance Variable — AP CSA Definition & Exam Guide

## Definition

A private instance variable is a field declared with the private access modifier inside a class, so only code within that class can read or change it directly; other classes must go through public methods like getters and setters, which is how Java enforces encapsulation on the AP CSA exam.

## What It Is

A private instance variable is a piece of data that belongs to an [object](/ap-comp-sci-a/key-terms/object "fv-autolink") and is marked with the `private` keyword, like `private double balance;` inside a `BankAccount` [class](/ap-comp-sci-a/unit-3/abstraction-and-program-design/study-guide/o9VgVeIpKRYZ7N7rXfUz "fv-autolink"). "Instance" means every object gets its own copy (your account's balance, my account's balance). "Private" means only code written inside that same class can touch it directly. If a client class tries `myAccount.balance`, the code won't even compile.

So how does anyone use the data? Through the class's [public](/ap-comp-sci-a/key-terms/public "fv-autolink") methods. A getter (accessor) like `getBalance()` returns the value, and a setter (mutator) like `deposit()` changes it in a controlled way. Think of it like an ATM. You never reach into the bank vault yourself. You make requests through a machine that follows the bank's rules. That gap between the data (hidden) and the interface (public) is the whole point of encapsulation, and it's a convention AP CSA treats as non-negotiable: instance variables should always be private.

## Why It Matters

[Private](/ap-comp-sci-a/key-terms/private "fv-autolink") instance variables live at the center of Unit 5 (Writing Classes), where you learn to design a class from scratch by choosing its data and its public interface. The CED's expectation is blunt: when you write a class, you declare instance variables as private and provide access only through methods. This idea also echoes backward into [Unit 2](/ap-comp-sci-a/unit-2 "fv-autolink") (Using Objects), where you call getters precisely because you can't reach the data directly, and forward into Unit 9 (Inheritance), where even a subclass cannot directly access its parent's private variables and must use inherited public or protected methods instead. If you understand why `private` exists, you understand data hiding, encapsulation, and why every released class design FRQ solution starts with private fields.

## Connections

### Encapsulation (Unit 5)

Encapsulation is the design principle; private [instance variables](/ap-comp-sci-a/key-terms/instance-variables "fv-autolink") are how you actually do it in Java. Marking data private and exposing it only through public methods means the class controls its own state instead of trusting every other class to behave.

### Public instance variable (Unit 5)

The anti-pattern. A public instance variable lets any class reach in and overwrite the data, which breaks data hiding. On the class design FRQ, declaring instance variables public instead of private costs you a rubric point.

### Data hiding (Unit 5)

Data hiding is the payoff of going private. The class can change how it stores information internally without breaking client code, because clients only ever talked to the public methods anyway.

### Inheritance and private access (Unit 9)

A common surprise: a subclass inherits its parent's private instance variables but cannot access them directly. The subclass has to call the parent's public getters or use [super](/ap-comp-sci-a/key-terms/super "fv-autolink")'s constructor, which is a favorite MCQ trap.

## On the AP Exam

This shows up two ways. In MCQs, you'll see code where a client class tries to access something like `account.balance` directly, and you have to recognize that it won't compile because `balance` is private. Questions ask things like "which code segment lets a client class access the private instance variable `balance`?" and the answer always routes through a public accessor method. Other MCQs test the purpose of getters and setters, which only exist because the underlying data is private. On the free response, the class design question (historically FRQ 2, like StepTracker in 2019) asks you to write a complete class. The scoring guidelines award a point for declaring appropriate private instance variables, so writing `private int totalSteps;` instead of `int totalSteps;` is literally worth points. Make `private` your default for every instance variable you write on the exam.

## Private instance variable vs Public instance variable

Both are fields that belong to an object; the difference is who can touch them. A public instance variable can be read and modified by any class (`account.balance = -5000;` would compile), while a private one can only be accessed inside its own class. AP CSA expects private. Public instance variables technically work in Java, but they destroy encapsulation, and on the FRQ they cost you the instance variable declaration point.

## Key Takeaways

- A private instance variable can only be accessed by code inside its own class; any other class trying to use it directly causes a compile-time error.
- Other classes interact with private data through public accessor (getter) and mutator (setter) methods, which is what encapsulation looks like in actual Java code.
- On the AP CSA class design FRQ, declaring your instance variables as private is part of the scoring rubric, so always write the private keyword.
- Each object gets its own copy of every instance variable, so two BankAccount objects have two separate private balance values.
- A subclass inherits its parent's private instance variables but cannot access them directly; it has to use the parent's public methods or constructor.

## FAQs

### What is a private instance variable in AP Computer Science A?

It's a field inside a class declared with the [private access modifier](/ap-comp-sci-a/key-terms/private-access-modifier "fv-autolink"), like `private double width;`. Only code within that same class can read or modify it directly, and other classes must use public methods like getters and setters.

### Can a subclass access a private instance variable from its parent class?

No. The subclass inherits the variable (the data exists in the object), but it cannot reference it directly by name. It has to use the parent's public getter methods or pass values up through `super()` in the constructor. This is a classic Unit 9 MCQ trap.

### What's the difference between a private instance variable and a local variable?

A private instance variable is declared in the class body, belongs to the object, and lives as long as the object does. A local variable is declared inside a method, has no access modifier, and disappears when the method finishes running.

### Do I lose points on the AP CSA FRQ if my instance variables aren't private?

Yes, on the class design free-response question (like StepTracker on the 2019 exam), the rubric awards a point for declaring appropriate private instance variables. Leaving off the private keyword or making them public costs you that point.

### If a variable is private, how do other classes get its value?

Through public accessor methods. For example, a BankAccount class with `private double balance;` provides a method like `public double getBalance() { return balance; }` so client classes can read the value without being able to change it directly.

## Structured Data

```json
{"@context":"https://schema.org","@graph":[{"@type":"LearningResource","@id":"https://fiveable.me/ap-comp-sci-a/key-terms/private-instance-variable#resource","name":"Private Instance Variable — AP CSA Definition & Exam Guide","url":"https://fiveable.me/ap-comp-sci-a/key-terms/private-instance-variable","learningResourceType":"Concept explainer","educationalLevel":"AP® / High School","about":{"@id":"https://fiveable.me/ap-comp-sci-a/key-terms/private-instance-variable#term"},"audience":{"@type":"EducationalAudience","educationalRole":"student"},"dateModified":"2026-06-11T00:50:32.739Z","isPartOf":{"@type":"Collection","name":"AP Computer Science A Key Terms","url":"https://fiveable.me/ap-comp-sci-a/key-terms"},"publisher":{"@type":"Organization","name":"Fiveable","url":"https://fiveable.me"}},{"@type":"DefinedTerm","@id":"https://fiveable.me/ap-comp-sci-a/key-terms/private-instance-variable#term","name":"Private instance variable","description":"A private instance variable is a field declared with the private access modifier inside a class, so only code within that class can read or change it directly; other classes must go through public methods like getters and setters, which is how Java enforces encapsulation on the AP CSA exam.","url":"https://fiveable.me/ap-comp-sci-a/key-terms/private-instance-variable","inDefinedTermSet":{"@type":"DefinedTermSet","name":"AP Computer Science A Key Terms","url":"https://fiveable.me/ap-comp-sci-a/key-terms"}},{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"What is a private instance variable in AP Computer Science A?","acceptedAnswer":{"@type":"Answer","text":"It's a field inside a class declared with the [private access modifier](/ap-comp-sci-a/key-terms/private-access-modifier \"fv-autolink\"), like `private double width;`. Only code within that same class can read or modify it directly, and other classes must use public methods like getters and setters."}},{"@type":"Question","name":"Can a subclass access a private instance variable from its parent class?","acceptedAnswer":{"@type":"Answer","text":"No. The subclass inherits the variable (the data exists in the object), but it cannot reference it directly by name. It has to use the parent's public getter methods or pass values up through `super()` in the constructor. This is a classic Unit 9 MCQ trap."}},{"@type":"Question","name":"What's the difference between a private instance variable and a local variable?","acceptedAnswer":{"@type":"Answer","text":"A private instance variable is declared in the class body, belongs to the object, and lives as long as the object does. A local variable is declared inside a method, has no access modifier, and disappears when the method finishes running."}},{"@type":"Question","name":"Do I lose points on the AP CSA FRQ if my instance variables aren't private?","acceptedAnswer":{"@type":"Answer","text":"Yes, on the class design free-response question (like StepTracker on the 2019 exam), the rubric awards a point for declaring appropriate private instance variables. Leaving off the private keyword or making them public costs you that point."}},{"@type":"Question","name":"If a variable is private, how do other classes get its value?","acceptedAnswer":{"@type":"Answer","text":"Through public accessor methods. For example, a BankAccount class with `private double balance;` provides a method like `public double getBalance() { return balance; }` so client classes can read the value without being able to change it directly."}}]},{"@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"AP Computer Science A","item":"https://fiveable.me/ap-comp-sci-a"},{"@type":"ListItem","position":2,"name":"Key Terms","item":"https://fiveable.me/ap-comp-sci-a/key-terms"},{"@type":"ListItem","position":3,"name":"Private instance variable"}]}]}
```
