AP (Advanced Placement) · AP Computer Science A

Abstraction, Program Design and Its Impact: Practice Questions

5 multiple-choice questions marked as you go, and 1 written questions with worked solutions. All on Abstraction, Program Design and Its Impact.

6 questions9 marksFree, no account
Question 1
1 mark

Consider the following class header for a class named Book. Which of the following is a valid constructor for this class if the class has private instance variables title (String) and pages (int)?

Question 2
1 mark

Which of the following best describes the purpose of a constructor in a Java class?

Question 3
1 mark

A class Student has an instance variable gpa. The constructor is defined as follows:

public Student(double gpa) {
gpa = gpa;
}

What happens when new Student(3.5) is called, assuming the instance variable is also named gpa?

Question 4
1 mark

A class Square is being designed. It needs to store the length of a side. Which of the following is the most appropriate way to declare the instance variable for side length to ensure encapsulation?

Question 5
1 mark

Consider the following class definition:

public class Runner {
private double distance;
public Runner(double d) {
distance = d;
}
public void addDistance(double d) {
distance += d;
}
}

If we execute the following code:
Runner r1 = new Runner(5.0);
r1.addDistance(2.5);
What is the value of distance in the object r1?

Question 6
4 marks

Part a: A software developer needs to create a Student class. Define a constructor that initializes a student's name (String) and their current GPA (double).
Part b: Write a method isEligible that returns true if the GPA is greater than or equal to 2.0, and false otherwise.
Part c: Explain why the instance variables should be declared as private and how the constructor helps in maintaining encapsulation.

Write your answer out first, then check it against the worked solution.

* The content provided by thinka is generated by AI and may not always be accurate or up-to-date. Please use it as a supplementary resource and verify with official materials.

You've seen the model answer. Now get yours marked.

This page can show you how a good answer looks. It cannot tell you what your answer was missing. thinka marks your written work against the real mark scheme in about 15 seconds.

Want more questions like these? Get a fresh set on this topic, marked as you go.

Practise More