Calling Methods With Parameters
Overview: 2.4.0
- Methods can take
argumentsorparametersto use variables within actual parametersorargumentsare put inside of the parenthesis of some methods- the
turnmethod of Turtle intakes an angle to turn a specific number of degreesturguggins.turn(100)to turn 100 degrees
- the
Parameters vs Arguments
- Variables defined as inputs to methods are
formal parameters- If I were to define a new function
makePizza(Cheese cheese, Sauce sauce, PizzaDough dough),cheese,sauceanddoughwould be formal parameters
- If I were to define a new function
- When a method is called, you pass
argumentsoractual parameterswhich are saved in the parameter variables- If I called my method with
makePizza(cheddar, marinara, wholeGrain),cheddar,marinara, andwholeGrainwould be arguments
- If I called my method with
Overloading
- a method is
overloadedwhen multiple methods with the same name, but with different parameters
Summary: 2.4.3
methodsare behaviors/functions objects cna do- called with the dot operator
turguggins.forward(30)
- called with the dot operator
- Some methods take parameters which are placed in the parenthesis
- Arguments must correspond with the type and order as defined in the parameter list created with the method signature

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
This was adapted from the CS Awesome curriculum, which was created by
Barbara Ericson, Beryl Hoffman, and many other CS Awesome contributors. All rights reserved.
CS Awesome is licensed under CC BY-NC-SA 4.0.