Skip to content

Return Methods

  • Lesson
  • 1 min read
  • 4 of 7 in this chapter

Methods like variables

In the last lesson, we went over void methods. These are methods that do not return a value.

Returning a value means that we can use methods like variables or even values, making calculations very easy to do.

We follow the same steps as creating a method, except we change two things:

  • Instead of void, we use a data type or object. We want the method to know what kind of value/variable it is returning
  • We also add return inside of the method, to choose what exactly is returned.

Let's try it with this example:

Java
public static void