AP Computer Science A · Topic 2.3
Calling a Void Method Practice
Part of Using Objects.
Practice questions
2
Want a predicted score for the whole AP CSA exam? Take the 20-question diagnostic and Lumi will plan the rest.
Sample questions
2 of 2 — sign in to practice the rest with adaptive difficulty and mastery tracking.
Sample 1difficulty 1/5
public class Printer { public void greet() { System.out.print("Hi"); } } // ... Printer p = new Printer(); int x = p.greet();What is the result?
- A
0
- B
null
- C
Hi
- Dcheck_circle
Compile-time error
Why
A void method has no return value, so it cannot be assigned to an int variable.
- A
Sample 2difficulty 3/5
Given <code>Dog d = new Dog("Rex");</code>, you call its bark method by
- A
bark.d()
- Bcheck_circle
d.bark()
- C
Dog.bark()
- D
d->bark()
Why
Instance method via dot notation; static would use <code>Dog.method()</code>.
- A