Attribute in AP Computer Science A

In AP Computer Science A, an attribute is the data related to a class, stored in variables (EK 1.7.A.2). For objects, attributes live in instance variables, and an object's attributes plus their current values make up its state (EK 3.4.A.1).

Verified for the 2027 AP Computer Science A examLast updated June 2026

What is attribute?

An attribute is any piece of data a class keeps track of. The CED says it plainly: attributes are "the data related to the class and are stored in variables" (EK 1.7.A.2). If a Car class has a brand and a year, those are its attributes. The variables that hold them, like private String brand; and private int year;, are instance variables.

Here's the mental model that makes it click. A class is the blueprint, and attributes are the blanks the blueprint says every object must fill in. When you write new Car("Toyota", 2020), the constructor fills in those blanks for one specific object. The attributes and their values at any moment are that object's state (EK 3.4.A.1). Two Car objects share the same attribute list because they come from the same class, but each one stores its own values. That's the has-a relationship: a Car has a brand, a Car has a year.

Why attribute matters in AP® Computer Science A

Attributes are the thread that ties Unit 1 (Using Objects and Methods) to Unit 3 (Class Creation). In Unit 1 you read attributes out of API documentation (LO 1.7.A) and understand that an object is "a specific instance of a class with defined attributes" (EK 1.12.A.1). In Unit 3 you flip from consumer to author. You declare instance variables for the attributes and initialize them in constructors (LO 3.4.A), mark them private for encapsulation (LO 3.3.A), and list every attribute and behavior when you design a class on paper or in a diagram (LO 3.1.A). Almost every class-design FRQ starts with one question in disguise: what data does this thing need to remember? That question is asking you to identify the attributes.

How attribute connects across the course

Behavior (Units 1 & 3)

Attributes and behaviors are the two halves of every class. Attributes are what an object knows (data in variables), behaviors are what it does (methods). When LO 3.1.A asks you to diagram a class, you list both, and a clean design pairs each attribute with the behaviors that read or change it.

Constructors (Unit 3)

A constructor's whole job is to give every attribute its starting value. EK 3.4.A.2 says the initial state should include initial values for all instance variables, with constructor parameters supplying the data. If a class has three attributes, expect the constructor to initialize all three.

Encapsulation and private access (Unit 3)

On the AP exam, attributes are declared private (EK 3.3.A). That hides the data inside the class, so outside code interacts with attributes only through public methods. Writing a public instance variable on a class-design FRQ costs you points.

Inheritance and the class hierarchy (Unit 1)

EK 1.12.A.2 explains that common attributes of related classes get pulled up into a superclass. Subclasses inherit those attributes instead of re-declaring them, which is the whole payoff of building a hierarchy.

Is attribute on the AP® Computer Science A exam?

Multiple-choice questions love the class-vs-object distinction, and attributes are the hinge. A typical stem shows code like Car myCar = new Car("Toyota", 2020); next to Car yourCar = new Car("Honda", 2019); and asks what it demonstrates. The answer hangs on knowing that both objects share the class's attribute definitions but hold different values, meaning different states. On the free-response side, the class-design FRQ hands you a description in plain English and expects you to translate the nouns into private instance variables (the attributes) and initialize every one of them in the constructor. Forgetting to declare an attribute private, or leaving one uninitialized in the constructor, are two of the most common ways to lose points on that question.

Attribute vs behavior

Attributes are data; behaviors are actions. An attribute is stored in a variable (a Car's brand), while a behavior is implemented as a method (a Car's drive()). Quick test when reading a class description: nouns usually become attributes, verbs usually become behaviors. The exam expects you to sort a scenario into both buckets when designing a class.

Key things to remember about attribute

  • An attribute is data related to a class, stored in variables, while a behavior is what objects of the class can do, implemented in methods.

  • An object's state is its attributes and their values at a given moment, and that state is defined by the object's instance variables (EK 3.4.A.1).

  • Every object of a class has the same set of attributes but stores its own values, which is why two Car objects can have different brands and years.

  • On the exam, attributes are declared as private instance variables and every one of them gets an initial value in the constructor.

  • An object has-a relationship with its instance variables, so when a description says a player has a score, that score is an attribute.

  • API documentation tells you a class's attributes and behaviors, which is how you use library classes you didn't write (EK 1.7.A.1).

Frequently asked questions about attribute

What is an attribute in AP Computer Science A?

An attribute is data related to a class, stored in variables (EK 1.7.A.2). For example, a Student class might have attributes like name and gpa, held in instance variables, and each Student object stores its own values for them.

Is an attribute the same thing as an instance variable?

Almost. The attribute is the concept (the piece of data a class tracks), and the instance variable is the Java code that stores it. The CED treats them as tightly linked: you "declare instance variables for the attributes" (LO 3.4.A), so in practice you can use the terms nearly interchangeably on the exam.

How is an attribute different from a behavior?

Attributes are the data an object stores in variables; behaviors are the actions an object performs through methods. A BankAccount's balance is an attribute, while deposit() and withdraw() are behaviors.

Do attributes have to be private on the AP exam?

Yes. EK 3.3.A.4 establishes that instance variables are declared private in this course, which keeps the data encapsulated. Classes and constructors are public, but the attributes stay private and are accessed through public methods.

Can two objects of the same class have different attribute values?

Yes, and that's the whole point of objects. The class defines which attributes exist, but each object gets its own copy with its own values, so new Car("Toyota", 2020) and new Car("Honda", 2019) are two objects with two different states.