Methods Flashcards
public static void main (String []args)
Identify the parts of the method.
void - return type
main - method name
(String []args) - parameter
What is the format of a method?
public static return_type methodName ([parameters])
It is a variable that will receive the value being passed in calling the method.
Parameters
This return type will not return any value.
void
a collection of statements that are grouped together to perform an operation.
Method
a collection of statements that are grouped together to perform an operation.
Method
Examples of defined methods in the Java library
- System.out.println
- Integer.parseInt,
- Double.parseDouble
- System.exit
- Math.pow
- Math.random.
Syntax in declaring method
[accesskeyword] static returntype methodname (parameter) {
}
can be public, private, or protected.
Access keyword
What will be the default form of access if no access modifier is declared?
Package
indicates the type of value returned or reported back to the calling method, and it is most often used in conjunction with the assignment of a value to a variable in the calling method.
Return type
What can the return type be?
- any Java primitive data type
- an object
- void
This return type denotes hat the method has no return value
Void
What naming rules does the method name follow?
Follows the same naming rules as variables and will generally begin with a lowercase letter.
What are methods and variables caused because they are both contained inside classes?
They are called class members
receives the value being passed when a function is called
Parameter
What is used to separate parameters in a parameter list?
Comma