6 - Methods
While you are programming, there may be parts of your code which you will want to re-use rather than re-writing them. That is where methods come in. Methods allow you to create blocks of code which have some functionality which can easily be used. In this tutorial I will teach you what makes up a method, and how to use them in your code.
Note: You may be wondering why methods are called methods instead of functions. Methods are essentially the OOP version of functions. There are a few slight differences between them, but for the most part they are the same.
Anatomy of a Method
<Type> <Name> (<Parameters>) { //do stuff code }
Name
Each method that you create will have a unique name assigned to it.
Parameters
Very often, you will want to pass in variables to a method you create. Parameters are the variables that you put into the parameter section of your method.
Return
Sometimes you will want to return some value when you call a method. Return types and the return keyword are how you will achieve this.
Video