What is a Java method?
A method is a named block of code that performs a task, can receive parameters, and may return a value.
Study 5 Methods and Modular Design with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.
What is a Java method?
A method is a named block of code that performs a task, can receive parameters, and may return a value.
What is modular design?
Modular design builds a program from small components that can be developed, tested, and reused independently.
What parts commonly make up a Java method declaration?
A Java method declaration commonly includes a modifier, return type, name, parameter list, and method body.
What is the difference between parameters and arguments?
Parameters are variables declared by a method to describe expected inputs; arguments are the actual values supplied when the method is called.
How is a Java method called?
A method call writes the method name followed by parentheses and begins executing that method with the supplied arguments.
What does the `void` return type mean?
`void` indicates that a method performs an action without returning a value. It may use `return;` to end execution early, but cannot return a value.
How does Java pass object and array arguments?
Java passes arguments by value. For objects and arrays, the copied value is a reference, so a method can change shared contents but cannot replace the caller's reference by reassigning its parameter.
Why return a calculation instead of always printing it?
A return value communicates a result to the caller, which can store, print, compare, or pass that result to another method.
What does variable scope mean?
Scope is the region of a program in which a declared name can be referred to. A local variable is normally available only within its method or declaration block.
What is decomposition in program design?
Decomposition divides a large problem into smaller tasks, assigns each task to a method, and combines those methods through a controlling method.
What does a method contract describe?
A method contract states its purpose, inputs, output, assumptions, and side effects.
What is method overloading?
Overloading defines methods with the same name but different parameter lists. The compiler selects the version whose parameter types match the call.