Calling Methods With Parameters
Overview: 2.4.0
- Methods can take
arguments
orparameters
to use variables within actual parameters
orarguments
are put inside of the parenthesis of some methods- the
turn
method 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
,sauce
anddough
would be formal parameters
- If I were to define a new function
- When a method is called, you pass
arguments
oractual parameters
which are saved in the parameter variables- If I called my method with
makePizza(cheddar, marinara, wholeGrain)
,cheddar
,marinara
, andwholeGrain
would be arguments
- If I called my method with
Overloading
- a method is
overloaded
when multiple methods with the same name, but with different parameters
Summary: 2.4.3
methods
are 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.