Search⌘ K

Parameters and Return Types in Methods

Explore how Java methods use parameters to receive input and return types to provide output. Understand the role of primitive and reference types, and learn the purpose of void methods. This lesson helps you effectively utilize methods within object-oriented programming.

We'll cover the following...

Parameters

The parameters are the inputs that a Java method takes. These are given as an ordered list in parentheses next to the name of the method. We can have any number of parameters.

  • If a method does not have any parameters, the parentheses are left empty.

    public static void function()
    {
      // implementation here
    }
    
  • Otherwise, for each parameter, we give the type and the name, separated by a comma, in the method’s signature.

...