Class Methods and the Math Class
Free AP Computer Science A multiple-choice practice for topics 1.10–1.11, Unit 1 (Using Objects and Methods). Answer five random questions, check your work, and review the essential knowledge behind each one.
Unit 1: Using Objects and Methods. Topics 1.10–1.11. This set has 55 questions. Each time the page loads you get five of them, chosen at random. Pick an answer, press Check answer, and read the explanation for every choice. Reload the page or use New questions for a fresh five.
Topics assessed
- 1.10 Calling Class Methods
- 1.11 Math Class
Practice questions
Loading questions…
Essential knowledge for this set
These are the essential knowledge (EKS) statements from the AP Computer Science A Course and Exam Description that the 55 questions in this set assess, grouped by topic and learning objective. The table under each question links here.
Topic 1.10: Calling Class Methods
1.10.A — Develop code to call class methods and determine the result of those calls.
- 1.10.A.1 Class methods are associated with the class, not instances of the class. Class methods include the keyword static in the header before the method name.
- 1.10.A.2 Class methods are typically called using the class name along with the dot operator. When the method call occurs in the defining class, the use of the class name is optional in the call.
Topic 1.11: Math Class
1.11.A — Develop code to write expressions that incorporate calls to built-in mathematical libraries and determine the value that is produced as a result.
- 1.11.A.1 The Math class is part of the java.lang package. Classes in the java.lang package are available by default.
-
1.11.A.2 The Math class contains only class methods. The following Math class methods—including what they do and when they are used—are part of the Java Quick Reference:
- static int abs(int x) returns the absolute value of an int value.
- static double abs(double x) returns the absolute value of a double value.
- static double pow(double base, double exponent) returns the value of the first parameter raised to the power of the second parameter.
- static double sqrt(double x) returns the nonnegative square root of a double value.
- static double random() returns a double value greater than or equal to 0.0 and less than 1.0.
- 1.11.A.3 The values returned from Math.random() can be manipulated using arithmetic and casting operators to produce a random int or double in a defined range based on specified criteria. Each endpoint of the range can be inclusive, meaning the value is included, or exclusive, meaning the value is not included.