Skip to main content

Final Keyword in AP Computer Science A

In AP Computer Science A, the final keyword marks a variable whose value cannot be modified once it is assigned (EK 3.7.B.3). It is often combined with static to create a shared class constant, such as public static final double TAX_RATE = 0.08;.

This definition is part of Fiveable's AP Computer Science A review, which also has guided practice questions.

Verified for the 2027 AP Computer Science A exam•Last updated October 2026•Fiveable Content Team

What is Final Keyword?

final is a Java keyword that says "this value is locked in." Once a final variable gets its value, any later attempt to assign a new one is a compile-time error. The code won't even run. The AP CED states it directly in EK 3.7.B.3: when a variable is declared final, its value cannot be modified.

You'll see final most often next to static. static makes one shared copy that belongs to the class. final makes that copy unchangeable. Put them together and you get a class constant:

</>Java
public static final int MAX_STUDENTS = 30;

By convention, constants are written in ALL_CAPS so you can spot them instantly. A final instance variable (no static) is also legal. Each object gets its own copy, set once (usually in the constructor), and then it never changes. One subtle point is that if a final variable holds an object reference, the reference is locked, not the object's contents. You can't point it at a different object, but you might still be able to change the object through its methods.

Why Final Keyword matters in AP® Computer Science A

Final lives in Unit 3: Class Creation, Topic 3.7 Static Variables and Methods. It's written right into the essential knowledge for AP Comp Sci A 3.7.B ("Develop code to declare the class variables that belong to the class") as EK 3.7.B.3. That objective is all about deciding how a variable should be declared. Does it belong to the class or to each object (static or not)? Should outside code see it (public or private)? Can it ever change (final or not)? Final answers that last question. It also ties into 3.7.A, because class methods can read class variables (EK 3.7.A.2), including static final constants. On the exam, this is part of writing well-designed classes. You use final when a value should never change, and you leave it off when the program needs to update the value.

How Final Keyword connects across the course

Static Class Variables (Unit 3)

Static and final answer two different questions. Static asks "who owns this?" (the class, with one shared copy per EK 3.7.B.1). Final asks "can it change?" (no, per EK 3.7.B.3). Think of static final as a value printed on the class's nameplate. Every object reads the same one, and nobody can edit it.

Public Access and the Dot Operator (Unit 3)

Constants are usually made public because there's no risk in sharing a value nobody can change. Per EK 3.7.B.2, outside code reaches a public class variable through the class name and the dot operator, like Math.PI or Student.MAX_GPA. You never need to create an object first.

Instance Variables and Constructors (Unit 3)

Final isn't only for static variables. A final instance variable, such as a bank account number, gives each object its own value. That value gets set once in the constructor and then stays frozen. It's a clean way to model data that is fixed per object but different across objects.

Immutable Objects (Unit 3)

Marking an object reference final stops you from reassigning the variable, but it doesn't freeze the object itself. An immutable object is one whose state can't change after it's built. Final is one tool for building immutable objects, but the two ideas are not the same thing.

Is Final Keyword on the AP® Computer Science A exam?

Final shows up mainly in multiple-choice questions about class design and variable declarations. Common stems give you a class with a /* missing declaration */ and ask which declaration fits the scenario. A BankAccount class with a shared interest rate or a fixed account number is a typical setup. Other questions ask which keyword makes a variable shared by all instances (that's static, not final), or which use of static is correct. To get these right, separate the jobs of each keyword. Static means shared and class-owned. Final means unchangeable. Public means accessible from outside. You may also need to spot a compile error, such as code that tries to reassign a final variable in a method. No released FRQ has used the term verbatim. Still, FRQs that ask you to write a full class reward correct declarations, and a static final constant for a fixed value is legitimate, readable design.

Final Keyword vs Static Keyword

Static controls ownership. A static variable belongs to the class, and every object shares one copy, but its value can still change (a static counter that increases each time an object is made). Final controls change. A final variable can never be reassigned, but it isn't necessarily shared. A non-static final instance variable gives each object its own locked value. If a question asks for a variable "shared by all instances," the answer is static. If it asks for a value that "cannot be modified," the answer is final. If it wants both, you need static final.

Key things to remember about Final Keyword

  • A variable declared final cannot have its value modified after it is assigned, which matches EK 3.7.B.3.

  • Trying to reassign a final variable causes a compile-time error, so the program will not run at all.

  • Static and final do different jobs, because static means the class owns one shared copy while final means the value can never change.

  • Combining public static final creates a class constant that outside code reads with the class name and the dot operator, like Math.PI.

  • A final instance variable gives each object its own fixed value, usually set once in the constructor.

  • When a final variable holds an object reference, you can't reassign the reference, but the object itself might still be changeable through its methods.

Frequently asked questions about Final Keyword

What does the final keyword do in Java for AP CSA?

It makes a variable unchangeable after it receives a value. The AP CED puts it in EK 3.7.B.3 under Topic 3.7, and it's most often paired with static to create class constants like public static final int MAX_SIZE = 100;.

Does final make a variable shared by all objects?

No. Sharing comes from static, not final. A final variable without static is an instance variable, so each object has its own separate value that just can't change.

What is the difference between static and final in Java?

Static means the variable belongs to the class and all objects share one copy (EK 3.7.B.1). Final means the value can't be modified (EK 3.7.B.3). A static counter can change, and a final instance variable isn't shared, so you need static final to get a shared constant.

Can you change an object if its variable is declared final?

Sometimes, yes. Final locks the reference, so you can't make the variable point to a different object. If the object has methods that modify its state, those still work unless the object is immutable.

Is the final keyword on the AP Computer Science A exam?

Yes. It's named in the essential knowledge for learning objective 3.7.B in Unit 3. It typically shows up in multiple-choice questions where you choose the right variable declaration or spot an illegal reassignment, and it's fair game when you write classes on FRQs.