Methods
Methods (known as functions in other coding languages) are blocks of code that you can easily reuse.
There are two types of methods— instance methods and static methods.
Creating Methods
A method's syntax is this:
[access modifier] [return type] methodName(parameters) {
[code]
}
Yes. I know this is confusing, especially if you've never touched programming before. Think of a method like a recipe.
A method's access modifier simply tells the code who can access this method. If the modifier is public, other files can access it. It's like a recipe found on Betty Crocker or something. If it's private, it's a super secret recipe, only for specific people you want to access.
The parameters are like the ingredients you need to make the meal. If any of the parameters you defined for the method aren't filled out, the method won't run. It's like trying to bake cookies without having flour or sugar.
The return type is like the final result of the cookbook. If everything in the method works properly- your recipe should give you a cool treat!
Challenge— Write a Cookbook
You can tell I'm really creative with this one. All you'll need to do is:
Last updated