Skip to content
Now Accepting Applications for 2027-2028Apply
ITMagicITMagicAcademy
AP resources
APComputer ScienceCSA

Objects & Classes (OOP)

AP Computer Science A — object-oriented programming in Java: classes, objects, instance variables, constructors and methods. Worked example and FRQ tip.

AP Computer Science A is built around object-oriented programming (OOP). A class is a blueprint; an object is a specific thing created from that blueprint.

Defining a class

public class Student {
  private String name;     // instance variable
  private int grade;

  public Student(String n, int g) {   // constructor
    name = n;
    grade = g;
  }

  public int getGrade() {   // method
    return grade;
  }
}

Creating and using objects

Student s = new Student("Ayşe", 11);
System.out.println(s.getGrade());   // 11
  • new calls the constructor and builds the object.
  • private instance variables are hidden — this is encapsulation. Outside code uses getter/setter methods instead of touching the data directly.

Worked example

What does s.getGrade() return above? It returns 11, the value passed to the constructor and stored in grade.

Exam tip

The CSA free-response section almost always asks you to write a class or a method. Practise the pattern: private instance variables, a constructor that sets them, and methods that use this/getters. Know the difference between an object reference and the object itself — two references can point to the same object, so changing one changes both.

Short Lesson Video

The lesson video for this topic will be added soon.

Mock Exam

The mock exam for this topic will be added soon.

Practice Quiz

Test yourself: instant results and explanations.

  1. 1. Which Java keyword creates a new object?

  2. 2. Making instance variables private and exposing them through getters/setters is an example of:

  3. 3. A class is best described as:

Need support with this topic?

In a free 30-minute intro call we assess your level and build a study plan tailored to you.

Free intro call