Unit 3 · Class Creation
Classes and Constructors
Practice mode with 15 Java-focused questions, immediate answer checks, and explanations.
What classes and constructors covers
A class defines instance variables that hold each object's state and constructors that initialize them. A constructor has the same name as the class and no return type, and it typically assigns its parameters into the instance variables. When a parameter shares a name with an instance variable, the parameter shadows it, and this.field = field; is what distinguishes the two. Instance variables not assigned in a constructor keep their type defaults.
Where students lose points
Declaring local variables inside the constructor with the same names as the instance variables means the object is never actually initialized, and every getter then returns a default. Students also give constructors a void return type, which quietly turns them into ordinary methods, and they forget this when shadowing occurs.
How it shows up on the AP exam
The heart of Unit 3. Class-writing FRQs award points specifically for correct instance variable declarations and a constructor that stores its parameters, so this topic is directly worth exam points.
For practice use only.
Classes and Constructors MCQ Practice
AP CSA class and constructor practice: instance variables, constructor parameters, the this keyword, and what default values objects start with.
Answered 0 of 15
Choose one answer.
Which option matches the complete output produced by this segment?
public class Tally
{
private int n;
public Tally(int start)
{
n = start;
}
public int get()
{
return n;
}
}
Tally t = new Tally(4);
System.out.print(t.get());