AP Computer Science A · Topic 2.5
Calling a Non-void Method Practice
Part of Using Objects.
Practice questions
4
Sample questions
4 of 4 — sign in to practice the rest with adaptive difficulty and mastery tracking.
Sample 1difficulty 3/5
For <code>String s = "hi";</code>, calling <code>s.length()</code> is
- Acheck_circle
Instance method call (on s)
- B
Constructor
- C
Static method call
- D
Compile error
Why
Instance methods called on object via dot notation.
- A
Sample 2difficulty 3/5
A method declared with return type <code>void</code>
- A
Returns 0
- B
Returns null
- C
Cannot return at all
- Dcheck_circle
Returns nothing (no value)
Why
<code>void</code> methods return no value; <code>return;</code> with no value is allowed.
- A
Sample 3difficulty 4/5
<code>" hello ".trim().toUpperCase()</code> returns
- Acheck_circle
HELLO
- B
HELLO
- C
hello
- D
hello
Why
<code>trim()</code> removes whitespace; <code>toUpperCase()</code> then capitalizes → "HELLO".
- A
Sample 4difficulty 4/5
A method declared as <code>public Dog clone()</code> returns
- A
An int
- B
void
- Ccheck_circle
A Dog object reference
- D
Compile error
Why
Return type Dog; method must return a Dog (or null).
- A