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. The public parts of a class form its interface, the set of doors other classes are allowed to walk through.
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.
Public shows up in the unit on writing classes, where you design your own classes and decide what's visible to the outside world, and it carries straight into inheritance, where a subclass interacts with its superclass through public constructors and methods. 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. It also explains a classic gotcha in inheritance questions. A subclass like Car extends Vehicle cannot directly touch Vehicle's private instance variables; it has to go through public methods or call the public superclass constructor with super(...).
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.
Inheritance and super (Unit 9)
A subclass inherits its parent's public methods but can't see its private variables. That's why Student extends Person must call the public Person constructor with super(n, a) instead of writing name = n directly. Inheritance MCQs love testing this exact gap.
On the multiple-choice section, public usually appears as part of the setup rather than the question itself. Every inheritance question hands you classes like public class Person with private instance variables and public constructors, then asks what a subclass can legally access. The trap answers are the ones where a subclass directly touches a private variable, which only works through public methods. 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. The 2017 exam shows the pattern everywhere, from the public interface StudyPractice in Q2 to the Phrase class in Q3, where you implement public methods that operate on private data. 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. The confusion usually hits with inheritance, because it feels like a subclass should inherit private variables. 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. If an answer choice has subclass code reading a private superclass variable directly, it's wrong.
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.
A subclass cannot directly access its superclass's private instance variables, even though it inherits them; it must use the superclass's public methods or call super(...) 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.
Yes. A subclass inherits all public methods of its superclass and can call them directly. What it cannot do is directly access the superclass's private instance variables, which is why subclass constructors call super(...) instead of assigning those variables themselves.
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.