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.
Public is one of Java's access modifiers, the keywords that control who is allowed to use a piece of your code. When something is marked public, any other class 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, 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.
Choosing the right access modifier 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...)`.
Keep studying AP® Computer Science A Unit 3
Private (Unit 5)
Public and private 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)
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)
The access modifier is the first word of a method header, 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 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 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.
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.
Public is an access modifier meaning any other class can access that class, constructor, or method. In AP CSA you'll declare classes, constructors, and methods public, like public class Vehicle or public int getYear().
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, which is the definition of encapsulation.
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.
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.
Connect this key term to the AP exam workflow: review the course, practice questions, and check related study tools.
Review units, study guides, and course resources.
Check this vocabulary in multiple-choice context.
Apply key concepts in written AP responses.
Estimate the exam score you are working toward.
Review the highest-yield facts before practice.
Put the full course together before test day.