A method is a named sequence of instructions that can be called or invoked to perform a specific task or action. Methods are used for code reusability, organization, and abstraction.
Imagine you have a recipe book with different cooking methods such as baking, frying, or grilling. Each method has step-by-step instructions for preparing specific dishes. Similarly, methods in programming contain sets of instructions that can be reused across different parts of your program.
Parameter: A parameter is an input variable passed into a method when it is called. It allows data to be passed from one part of the program to another.
Return Type: The return type specifies the type of value that will be returned by a method after it completes its execution.
Void Method: A void method does not return any value after execution; it performs certain actions but does not produce an output.
© 2024 Fiveable Inc. All rights reserved.
AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.