Parameters

Parameters

They are similar to instance variables in that they only work in a certain part of the code, but because they are essentially declared in the heading/declaration of a method or constructor they always apply to the whole method or constructor. Parameters are the values that the piece of the code that called the method sends for the method to use. For example say there was a method that gave you the value of a number ( say i ) to the i-th power. They would need to know the value of the number you want to have go through the program, so they have you send them that value when you call the method. It wouldn’t make sense to make a different method for every number, which would also be fairly impossible to do in a timely manner.

A parameter is as said before declared in the heading of a method or constructor.

An example of how to declare it is shown below:

Public (static) datatype methodName(datatype parameterName1, datatype parameterName2)

The actual parameter declaration is in italics, the rest is the method heading.

One thought on “Parameters

Comments are closed.