---
title: "Public — AP Computer Science A Definition & Exam Guide"
description: "Public is the Java access modifier that makes a class, method, or constructor visible to all other classes. Learn how AP CSA tests public vs. private."
canonical: "https://fiveable.me/ap-comp-sci-a/key-terms/public"
type: "key-term"
subject: "AP Computer Science A"
unit: "Unit 3"
---

# Public — AP Computer Science A Definition & Exam Guide

## Definition

In AP Computer Science A, public is the Java access modifier that gives a class, constructor, or method unrestricted visibility, meaning any other class can use it; on the AP exam, classes, constructors, and methods are written as public while instance variables are kept private.

## What It Is

**Public** is one of Java's [access modifiers](/ap-comp-sci-a/key-terms/access-modifiers "fv-autolink"), the keywords that control who is allowed to use a piece of your code. When something is marked `public`, any other [class](/ap-comp-sci-a/unit-3/abstraction-and-program-design/study-guide/o9VgVeIpKRYZ7N7rXfUz "fv-autolink") can see it and call it. That's why you'll see `public class Vehicle`, `public Vehicle(String make, int year)`, and `public String getMake()` all over AP code.

AP CSA follows a strict convention you should burn into memory. Classes, [constructors](/ap-comp-sci-a/unit-3/constructors/study-guide/3Ez6zzak2wRwMrTj2ZQk "fv-autolink"), and most methods are declared `public` so other code can create objects and call their behaviors. Instance variables are declared `private` so other classes can't reach in and mess with an object's data directly. If outside code needs that data, it goes through public accessor (getter) and mutator (setter) methods. This pairing of public methods with private data is the heart of encapsulation, one of the big ideas behind object-oriented design on the exam.

## Why It Matters

Choosing the right [access modifier](/ap-comp-sci-a/key-terms/access-modifier "fv-autolink") is the mechanical skill behind encapsulation. On the exam, writing `private` where the scoring guidelines expect `public` (or vice versa) can cost you points on FRQ 2, the class design question, which always asks you to write a complete class with correct visibility...)`.

## Connections

### [Private (Unit 5)](/ap-comp-sci-a/key-terms/private)

Public and [private](/ap-comp-sci-a/key-terms/private "fv-autolink") are two settings on the same dial. Public means everyone can access it, private means only code inside the same class can. The AP pattern is simple: methods public, instance variables private.

### [Access Modifiers (Unit 5)](/ap-comp-sci-a/key-terms/access-modifiers)

Public is one member of the access modifier family. Java also has protected and default (package-private), but the AP CSA exam only tests public and private, so those two are the ones you actually need to use correctly.

### [Method Header (Unit 5)](/ap-comp-sci-a/key-terms/method-header)

The access modifier is the first word of a [method header](/ap-comp-sci-a/key-terms/method-header "fv-autolink"), as in `public int getYear()`. When an FRQ gives you a method header to implement, copying it exactly, public keyword included, is the easiest point you'll earn all day.

## On the AP Exam

On the multiple-choice section, public usually appears as part of the setup rather than the question itself. On the free-response section, FRQ 2 (class design) requires you to write a full class, and the scoring guidelines expect public for the class, constructor, and methods and private for instance variables. When the prompt gives you a method header, reproduce its access modifier exactly.

## public vs Private

Public means any class anywhere can access it. Private means only code inside the same class can. It does inherit them in memory, but it cannot access them by name. A `Car` object has a `make`, but the `Car` class can only reach it through `Vehicle`'s public methods or constructor.

## Key Takeaways

- Public is the Java access modifier that lets any other class access a class, constructor, or method.
- The AP CSA convention is fixed: classes, constructors, and methods are public, while instance variables are private.
- ..) in its constructor.
- Public methods like getters and setters are the controlled doorway to private data, which is what encapsulation means in practice.
- On FRQ 2 (class design), using the wrong access modifier, like making instance variables public, can cost you points.
- The AP exam only tests public and private; protected and package-private exist in Java but are outside the CSA subset.

## FAQs

### What does public mean in Java for AP Computer Science A?

Public is an access modifier meaning any other class can access that class, [constructor](/ap-comp-sci-a/unit-1/creating-and-storing-objects/study-guide/rUOTKl6Ih5noXJ0GtxJF "fv-autolink"), or method. In AP CSA you'll declare classes, constructors, and methods public, like `public class Vehicle` or `public int getYear()`.

### What's the difference between public and private in Java?

Public members can be accessed from any class; private members can only be accessed by code inside the same class. AP code pairs them: public methods give controlled access to private [instance variables](/ap-comp-sci-a/key-terms/instance-variables "fv-autolink"), which is the definition of encapsulation.

### Should instance variables be public or private on the AP exam?

Private, always. The AP CSA scoring guidelines expect instance variables to be private with public getter and setter methods when outside access is needed. Declaring instance variables public on FRQ 2 can cost you points.

### Is protected on the AP Computer Science A exam?

No. The AP CSA Java subset only tests public and private. Protected and default (package-private) access exist in Java, but you won't be asked to use or interpret them on the exam.

## Related Study Guides

- [3.4 Constructors](/ap-comp-sci-a/unit-3/constructors/study-guide/3Ez6zzak2wRwMrTj2ZQk)
- [3.3 Anatomy of a Class](/ap-comp-sci-a/unit-3/anatomy-of-a-class/study-guide/DcGY5KOyK98H9Fn2w8jh)
- [3.6 Accessor Methods](/ap-comp-sci-a/unit-3/accessor-methods/study-guide/aGdfIlIw7aOvNseJG5R1)
- [1.10 Calling a Non-Void Method](/ap-comp-sci-a/unit-1/calling-non-void-method/study-guide/gXkdn6sNrkDRHZsCVN1x)
- [3.5 Writing Methods](/ap-comp-sci-a/unit-3/writing-methods/study-guide/rtuMpRFmidkpYTzvDndS)

## Structured Data

```json
{"@context":"https://schema.org","@graph":[{"@type":"LearningResource","@id":"https://fiveable.me/ap-comp-sci-a/key-terms/public#resource","name":"Public — AP Computer Science A Definition & Exam Guide","url":"https://fiveable.me/ap-comp-sci-a/key-terms/public","learningResourceType":"Concept explainer","educationalLevel":"AP® / High School","about":{"@id":"https://fiveable.me/ap-comp-sci-a/key-terms/public#term"},"audience":{"@type":"EducationalAudience","educationalRole":"student"},"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/public#term","name":"public","description":"In AP Computer Science A, public is the Java access modifier that gives a class, constructor, or method unrestricted visibility, meaning any other class can use it; on the AP exam, classes, constructors, and methods are written as public while instance variables are kept private.","url":"https://fiveable.me/ap-comp-sci-a/key-terms/public","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 does public mean in Java for AP Computer Science A?","acceptedAnswer":{"@type":"Answer","text":"Public is an access modifier meaning any other class can access that class, [constructor](/ap-comp-sci-a/unit-1/creating-and-storing-objects/study-guide/rUOTKl6Ih5noXJ0GtxJF \"fv-autolink\"), or method. In AP CSA you'll declare classes, constructors, and methods public, like `public class Vehicle` or `public int getYear()`."}},{"@type":"Question","name":"What's the difference between public and private in Java?","acceptedAnswer":{"@type":"Answer","text":"Public members can be accessed from any class; private members can only be accessed by code inside the same class. AP code pairs them: public methods give controlled access to private [instance variables](/ap-comp-sci-a/key-terms/instance-variables \"fv-autolink\"), which is the definition of encapsulation."}},{"@type":"Question","name":"Should instance variables be public or private on the AP exam?","acceptedAnswer":{"@type":"Answer","text":"Private, always. The AP CSA scoring guidelines expect instance variables to be private with public getter and setter methods when outside access is needed. Declaring instance variables public on FRQ 2 can cost you points."}},{"@type":"Question","name":"Is protected on the AP Computer Science A exam?","acceptedAnswer":{"@type":"Answer","text":"No. The AP CSA Java subset only tests public and private. Protected and default (package-private) access exist in Java, but you won't be asked to use or interpret them on the exam."}}]},{"@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":"Unit 3","item":"https://fiveable.me/ap-comp-sci-a/unit-3"},{"@type":"ListItem","position":4,"name":"public"}]}]}
```
