What you have is a method
why?
In Java, method declarations have five components, in order:
- Modifierssuch as
public
, private
, and others you will learn about later.
- The return typethe data type of the value returned by the method, or
void
if the method does not return a value.
- The method namethe rules for field names apply to method names as well, but the convention is a little different.
- The parameter list in parenthesisa comma-delimited list of input parameters, preceded by their data types, enclosed by parentheses,
()
. If there are no parameters, you must use empty parentheses.
- The method body, enclosed between bracesthe method's code, including the declaration of local variables, goes here.
public Polygon polygonFrom(Point[] corners) {
// method body goes here
}
Analyze your code snippet :
1. public is modifier
2. Polygon is return type
3. plygonForm is method name
4. (Point[] corners) is the parameter list in parenthesis
5. {} is a method body