Q1
Methods
Answer: Methods can be used to define reusable code and organize and simplify
coding. It is a group of statements grouped together to perform an operation Pg. 204
Q2
Defining a method
Answer: A method definition consists of its method name, parameters, return value
type, and body Pg. 204
Q3
Syntax for defining a method
Answer: modifier returnValueType methodname (list of parameters) { // method body
} Example: public static int max(int num1, int num2){ //method body } Pg. 204
Q4
Calling a method
Answer: Calling a method executes the code in the method To execute a method you
have to call or invoke it There are two ways to call / invoke a method depending on
whether the method returns a value or not Pg. 205
Q5
If the method returns a value
Answer: If the method returns a value, a call to the method is usually treated as a
value. For example: int larger = max(3, 4); This right here calls max(3, 4) and assigns
the result of the method to the variable larger. Example: System.out.println(max(3,
4)); This call is treated as a value, and it returns the value of the method call max(3,
4), which prints out the return value Pg. 206
Q6
If the method returns void
Answer: If a method returns void, a call to the method must be a statement. For
example, the method printLn returns void. The following call is a statement:
System.out.println("Welcome to Java!"); Pg. 206