slug
unit1test1
type
Post
status
Published
category
8-AP CSA
date
Aug 10, 2026
summary
tags
quiz
password
icon
 

AP Computer Science A — Unit 1

Multiple-Choice Questions

Using Objects and Methods — 42 Questions


1.1 Algorithms, Programming, and Errors

1. Which of the following best describes an algorithm?
A. A Java source file
B. A sequence of clear, ordered steps used to solve a problem
C. A program that has already been compiled
D. A collection of Java classes

2. Consider the following code.
What is printed?
A. 7
B. 15
C. 21
D. 35

3. Which of the following is a syntax error?
A.
B.
C.
D.

1.2 Variables and Data Types

4. Which declaration correctly creates a variable that stores the value 3.14?
A.
B.
C.
D.

5. Which of the following is a primitive type in Java?
A. String
B. Student
C. double
D. Scanner

6. Which statement about the following values is correct?
A. Both are boolean values.
B. Both are String values.
C. true is boolean and "true" is String.
D. true is String and "true" is boolean.

1.3 Expressions and Output

7. What is printed by the following code?
A.
B.
C.
D. Nothing is printed.

8. Which statement correctly prints the following text?
A.
B.
C.
D.

9. What is printed?
A. 2
B. 3
C. 3.4
D. 4

10. What is printed?
A. 2
B. 3
C. 3.4
D. 5

11. What is the value of the following expression?
A. 2
B. 4
C. 7
D. 12

12. What is printed?
A. 2
B. 2.0
C. 2.5
D. The code does not compile.

1.4 Assignment and Initialization

13. What is the value of x after the following statements execute?
A. 8
B. 9
C. 16
D. The code does not compile.

14. Consider the following code.
What happens?
A. 0 is printed.
B. null is printed.
C. A compile-time error occurs because the local variable has not been initialized.
D. A NullPointerException occurs.

1.5 Casting and Ranges of Values

15. What is the value of y?
A. 7
B. 8
C. 7.9
D. The code does not compile.

16. What is the result of the following expression?
A. -4
B. -3
C. 3
D. 3.99

17. What is printed?
A. 2
B. 2.0
C. 2.5
D. 3.0

18. What is printed?
A. 2.0
B. 2.5
C. 3.0
D. The code does not compile.

19. Consider the following code.
What is the value of x?
A. 2147483648
B. 2147483647
C. -2147483648
D. A compile-time error occurs.

20. Why might the following expression not produce exactly 0.3?
A. Integer overflow
B. Floating-point round-off error
C. Integer division
D. A syntax error

1.6 Compound Assignment Operators

21. What is the final value of x?
A. 12
B. 16
C. 18
D. 20

22. Which statement is equivalent to
A.
B.
C.
D.

23. What is printed?
A. 3
B. 5
C. 7
D. 10

1.7 APIs and Libraries

24. When reading an API, which information is most useful for determining whether a method call is valid?
A. The color of the IDE
B. Parameter types and their order
C. The number of comments in the program
D. The name of the source file

25. A programmer uses
without knowing how sqrt internally calculates a square root.
This is an example of
A. overflow
B. casting
C. abstraction
D. concatenation

1.8 Documentation and Preconditions

26. Suppose a method has the following documentation.
Which statement best describes the precondition?
A. The method always changes radius to 0.
B. The caller is expected to provide a nonnegative value for radius.
C. The method must return a negative number.
D. The compiler automatically checks that radius >= 0.

1.9 Method Signatures

27. Consider the method.
In the method definition, x is
A. an argument
B. a parameter
C. a constructor
D. an object

28. Consider the call
The value 5 is
A. a parameter
B. a method signature
C. an argument
D. a return type

29. Which of the following represents the method signature of this method?
A. double calculate
B. calculate(int, double)
C. public static double
D. calculate(x, y, double)

30. Which statement about a void method is correct?
A. It must return an int.
B. It does not return a value to the caller.
C. It cannot have parameters.
D. It must be an instance method.

31. Which pair of methods demonstrates method overloading?
A.
B.
C.
D.

1.10 Class Methods

32. Which of the following is a class method call?
A.
B.
C.
D.

1.11 Math Class

33. What is the result of the following expression?
A. -3.5
B. 3
C. 3.5
D. 4.0

34. What is the type of the value returned by
A. int
B. double
C. boolean
D. String

35. Which range correctly describes the possible values returned by
A. (0.0 < x < 1.0)
B. (0.0 \le x < 1.0)
C. (0.0 < x \le 1.0)
D. (0.0 \le x \le 1.0)

36. Which expression generates an integer from 5 through 12, inclusive?
A.
B.
C.
D.

1.12–1.14 Objects, Constructors, and Instance Methods

37. Which statement is correct?
A. An object is a blueprint for a class.
B. A class is an instance of an object.
C. A class is a blueprint, and an object is an instance of that class.
D. Classes and objects are primitive types.

38. What happens when the following code executes?
A. n becomes 0.
B. n becomes -1.
C. A compile-time error occurs.
D. A NullPointerException occurs at run time.

39. Suppose the Student API contains only the following constructor.
Which object creation is valid?
A.
B.
C.
D.

40. Consider the following code.
What is stored in part?
A. "com"
B. "pute"
C. "puter"
D. "computer"

1.15 Strings

41. What is printed by the following code?
A. HELLO
B. hello
C. Hello
D. The code does not compile.

42. Consider the following statements.
Which of the following is true?
A.
B.
C.
D.

 
 
 
public static void main(String[] args) Unit 1- Test- 01 答案
Loading...