java - Is this a class, constructor, or method? -
this question has answer here:
- methods vs constructors in java 9 answers
i'm having trouble identifying is. @ point, familiar methods, constructors, , class declarations like. this? why constructor , method had baby?
public polygon polygonfrom(point[] corners) { // method body goes here }
what have method
why?
in java, method declarations have 5 components, in order:
- modifierssuch
public
,private
, , others learn later. - the return typethe data type of value returned method, or
void
if method not return value. - the method namethe rules field names apply method names well, convention little different.
- the parameter list in parenthesisa comma-delimited list of input parameters, preceded data types, enclosed parentheses,
()
. if there no parameters, must use empty parentheses. - the method body, enclosed between bracesthe method's code, including declaration of local variables, goes here.
public polygon polygonfrom(point[] corners) { // method body goes here }
analyze code snippet :
1. public modifier
2. polygon return type
3. plygonform method name
4. (point[] corners) parameter list in parenthesis
5. {} method body