• Skip to main content
  • Skip to secondary menu
  • Skip to primary sidebar

JavaTutorOnline

1-on-1 Online Java Training by a Senior Software Engineer

  • Home
  • AP CSA
    • FRQ Practice
      • Arrays
      • ArrayList
      • Strings
      • 2D Arrays
    • MCQ Practice
      • Booleans
      • Iteration
      • Arrays
      • View all Units
  • Courses
  • Tutorials
    • Java
    • Servlets
    • Struts
    • Spring
    • Webservice
  • FAQ
  • Testimonials
  • Blog
  • CONTACT US

AP CSA Unit 1 Foundation Practice Assessment

Home » AP CSA MCQ » Unit 1 » Mock Exam

AP CSA Unit 1 Foundation Practice Assessment

📝 Foundation Assessment ⏱️ 40 Min Practice ✅ 20 Questions

Welcome to the Unit 1 Foundation Practice Assessment. This 20-question assessment focuses on foundational Java concepts currently covered in this practice collection, including variables, arithmetic expressions, casting, remainder operations, and compound assignment.

Exam Instructions: You have roughly 2 minutes per question. Have scratch paper ready to trace variable updates. Pay close attention to integer division, casting, operator precedence, remainder operations, and compound assignment.

Unit 1 Foundation Practice Assessment

Question 1 of 20 | Score: 0
1. Consider the following code segment. What gets printed?
int a = 7;
int b = 2;
double result = a / b;
System.out.println(result);
Correct Answer: B Because a and b are both integers, a / b performs integer division first. 7 / 2 truncates to 3. After the integer division evaluates, the result is implicitly widened to a double (3.0) and stored in result.
2. Which of the following correctly rounds the positive double variable myVal to the nearest integer?
Correct Answer: C Adding 0.5 before casting to an integer is the AP standard algorithm for rounding positive numbers. The cast (int) truncates the decimal portion, completing the rounding process.
3. Consider the following code segment. What is the output?
int x = 5;
x *= 2 + 4;
System.out.println(x);
Correct Answer: B Compound operators treat the entire right-hand side as if it were in parentheses. x *= 2 + 4; translates to x = x * (2 + 4);. Thus, 5 * 6 evaluates to 30.
4. Consider the following code segment. What gets printed?
System.out.println(17 % 5);
Correct Answer: A The modulo operator finds the remainder of division. 5 goes into 17 three times (15), leaving a remainder of 2.
5. Consider the following code segment. What gets printed?
int num1, num2 = 10;
System.out.println(num1 + num2);
Correct Answer: D The statement int num1, num2 = 10; declares both variables but only initializes num2. Because num1 is uninitialized, trying to add it causes a compile-time error.
6. Consider the following expression. What is printed?
int result = 8 – 4 / 2 + 1;
System.out.println(result);
Correct Answer: C Division happens first: 4 / 2 evaluates to 2. The expression becomes 8 - 2 + 1. Subtraction and addition are evaluated left to right: 6 + 1 equals 7.
7. Consider the following code segment. What gets printed?
System.out.println(“Answer: ” + (5 + 2));
Correct Answer: B The parentheses around (5 + 2) force the mathematical addition to occur first, yielding 7. That integer is then concatenated to the String.
8. Consider the following code segment. What gets printed?
System.out.println(17 % 5);
Correct Answer: B The remainder operator returns the remainder after integer division. 17 / 5 has quotient 3 with remainder 2, so 17 % 5 is 2.
9. Assume int val = 8;. Which of the following accurately subtracts 1 from val?
I. val = val – 1;
II. val -= 1;
III. val–;
Correct Answer: D All three are valid, functionally equivalent ways to decrement an integer variable by 1 in Java.
10. Consider the following code segment. What gets printed?
double value = 5.99;
int truncated = (int) value;
System.out.println(truncated);
Correct Answer: A Explicitly casting a double to an int completely discards the decimal portion without rounding. 5.99 simply truncates to 5.
11. Consider the following expression. What is printed?
System.out.println(20 / 3 * 2);
Correct Answer: C Division and multiplication have equal precedence and are evaluated strictly from left to right. First, 20 / 3 evaluates to 6 via integer division. Then, 6 * 2 evaluates to 12.
12. Which of the following variable declarations will cause a compilation error?
Correct Answer: B You cannot implicitly assign a double to an int because it results in a loss of precision. A compilation error is thrown unless explicit casting is used.
13. Consider the following code segment. What is printed?
int x = 7;
int y = 10;
System.out.println(x % y);
Correct Answer: B When using the modulo operator where the dividend (7) is smaller than the divisor (10), the divisor goes in zero times, leaving the entire dividend (7) as the remainder.
14. Consider the following code segment. What is printed?
double result = (double) 15 / 4;
System.out.println(result);
Correct Answer: C Because the cast (double) is immediately adjacent to the 15, it casts the 15 to 15.0 before the division occurs. The operation 15.0 / 4 forces floating-point division, yielding 3.75.
15. Consider the following sequential updates. What gets printed?
int k = 8;
k += 4;
k %= 5;
System.out.println(k);
Correct Answer: C 1. k += 4; updates k to 12.
2. k %= 5; evaluates the remainder of 12 divided by 5, which is 2.
16. Which of the following correctly extracts the last two digits (45) from the integer num = 8245;?
Correct Answer: C Modulo by a power of 10 extracts that many digits from the right side of an integer. 8245 % 100 divides by 100 and returns the remainder, which is 45.
17. Consider the following code segment. What gets printed?
int value = 6;
value *= 3 + 1;
System.out.println(value);
Correct Answer: B Compound assignment evaluates the entire right-hand side before applying the operator. value *= 3 + 1; is equivalent to value = value * (3 + 1);. Therefore, 6 * 4 = 24.
18. Consider the following code segment. What gets printed?
int a = 3;
int b = a;
b++;
System.out.println(a + ” ” + b);
Correct Answer: C When int b = a; executes, the value of a is copied into b. Incrementing b later does not change a, so the output is 3 4.
19. Consider the following code segment. What gets printed?
final int LIMIT = 50;
int num = 10;
num = LIMIT – 5;
System.out.println(num);
Correct Answer: C The final keyword prevents LIMIT from being changed, but its value (50) can be read and used in mathematical operations. LIMIT - 5 evaluates to 45, which is legally stored in the non-final variable num.
20. Consider the following expression. What is the value of result?
int result = (int) (12.5 % 3) + 2;
Correct Answer: C 12.5 % 3 is 0.5. Casting 0.5 to int gives 0, and then 0 + 2 gives 2.

Unit 1 Mock Exam Complete!

0 / 20

Return to MCQ Hub

Congratulations on Completing Unit 1!

If you scored 18 or higher, you have demonstrated strong command of the foundational concepts covered in this practice assessment. Review any questions you missed and continue with the current Unit 1 practice topics.

These foundational Java concepts support the rest of AP Computer Science A. Continue with the current Unit 1: Using Objects and Methods practice to work on the remaining Unit 1 topics.

← Return to Unit 1 Hub
Continue Unit 1 Practice →

Primary Sidebar

Mr Chinmay

Chinmay Patel
Book a Demo Class

Phone & Whatsapp +919853166385
javatution@gmail.com

Recent Posts

  • Learn Java in One Day: 10-Hour 1-on-1 Crash Course | JavaTutorOnline
  • Constructor in Java: Examples, Types & Constructor Overloading
  • Important Interview Questions on Java Multithreading
  • React Spring Boot Web Services React Integration
  • Spring Boot RESTful Web Services Example
  • Top Spring MVC Interview Questions and Answers for Developers
  • Top Spring Core Interview Questions and Answers for Developers
  • Host Java Web Apps for Free on Mobile with Tomcat and Termux
  • How to Deploy Java Web Application on Aws EC2 with Elastic IP
  • Simple Jsp Servlet Jdbc User Registration using Tomcat Mysql and Eclipse

Additional Resources

  • AP Computer Science A Summer Prep
Copyright © 2026 JavaTutorOnline