3️⃣

11.3 Method Calls

Calling a method is the formal way to say using a method. When you call a method, you execute all of the code which is inside of the method’s body (the stuff in the curly braces).

You call a method by using the method’s name, followed by parentheses and a semicolon. You can add arguments into the parentheses if you want to pass information into the method. You can think of arguments as options you have to change the behavior of a method. For example, I could have a method called scoopIceCream(), and I could pass the argument “chocolate” into the method to tell the method what flavor of ice cream I want it to scoop for me.

For example, the method sum() is called in the main method below. The sum() method takes 2 arguments, 5 and 4.

public static void main(String[] args) {
		sum(5, 4);
}

Previous Section

Next Section

⚖️

Copyright © 2021 Code 4 Tomorrow. All rights reserved. The code in this course is licensed under the MIT License. If you would like to use content from any of our courses, you must obtain our explicit written permission and provide credit. Please contact classes@code4tomorrow.org for inquiries.