AP® Computer Science A · Unit 3 · Topic 3.5

void Methods versus Methods That Return

Watch it explained

  1. How it worksHow does return hand a value back to the exact spot where the call was made?
  2. Worked exampleTrace a getArea call and find where its returned value lands in the calling statement.
  3. Common mistakeWhy doesn't any code written after a return statement ever get to run?
  4. Worked exampleFind what happens when a return sits inside an if inside a loop and the test passes.

Check yourself

Your turn1 of 2
A method contains: return total; System.out.println("done"); What happens to the println line?

End of topic.