AP (Advanced Placement) · AP Computer Science A

Abstraction, Program Design and Its Impact:練習題

5 條多項選擇題即時批改,另有 1 條文字題附完整解題步驟,全部圍繞「Abstraction, Program Design and Its Impact」。

6 條題目9 免費,無需登記
第 1 題
1

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)?

第 2 題
1

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

第 3 題
1

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?

第 4 題
1

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?

第 5 題
1

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?

第 6 題
4

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.

先自己寫一次答案,再對照解題步驟。

* thinka提供的內容由AI生成,可能並非總是準確或最新。請將其用作輔助資源,並與官方材料進行核實。

你已看過標準答案,接下來輪到批改你的答案。

這一頁可以告訴你好答案的樣子,卻無法指出你的答案欠缺什麼。thinka 按真實評分準則批改你的文字答案,約 15 秒完成。

想多做幾條同類題目?立即開始練習呢個課題,即做即批改。

立即練習