AP Computer Science A · Topic 2.4
Calling a Void Method with Parameters Practice
Part of Using Objects.
Practice questions
3
Want a predicted score for the whole AP CSA exam? Take the 20-question diagnostic and Lumi will plan the rest.
Sample questions
3 of 3 — sign in to practice the rest with adaptive difficulty and mastery tracking.
Sample 1difficulty 3/5
public class Cell { public int v; } public class Helper { public static void bump(Cell c) { c.v++; } } // ... Cell c = new Cell(); c.v = 10; Helper.bump(c); System.out.println(c.v);What is printed?
- Acheck_circle
11
- B
10
- C
0
- D
Compile-time error
Why
The reference is passed by value; bump modifies the same object's field through that reference.
- A
Sample 2difficulty 3/5
public class Helper { public static void fill(int[] a) { a[0] = 99; } } // ... int[] arr = {1, 2, 3}; Helper.fill(arr); System.out.println(arr[0]);What is printed?
- Acheck_circle
99
- B
1
- C
0
- D
Compile-time error
Why
Arrays are reference types; the method modifies the same array object, so arr[0] becomes 99.
- A
Sample 3difficulty 3/5
public class Helper { public static void inc(int n) { n++; } } // ... int x = 5; Helper.inc(x); System.out.println(x);What is printed?
- Acheck_circle
5
- B
6
- C
0
- D
Compile-time error
Why
Java passes primitives by value; modifying the parameter n inside inc does not affect x.
- A