what are method outlines ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

what are method outlines ?

rules for method in java

11th Dec 2017, 6:36 PM
Suresh Reddy Palagiri
Suresh Reddy Palagiri - avatar
1 Answer
0
Methods are composed by 5 elements: METHOD SYNTAX: [Access modifier][Visibility][Return type][Method name] {Parameters} DETAILS: * ACCESS MOD (Optional): > private > public > protected * VISIBILITY (Optional): OPTIONS: > static (Denies the method as belonging to a single object) * RETURN TYPE (Mandatory, except for Constructors): OPTIONS: > primitive types (int, char...) > arrays > Objects (Custom types) > void (For non-returning methods) * METHOD NAME (Mandatory, for storage purposes): Custom * PARAMETERS (Optional): DEFINITION: A list of variables to be passed into the method. SYNTAX (Each list item): [Parameter type][Parameter name (Identifier)] CODE EXAMPLES: public static void main(String args[]) { // *** CODE *** // returns nothing } float sum(float n1, float n2) { return n1 + n2: } int[] getSequence(int start, int end) { // returns an array return new int[] {start, end}; } OBS: The return keyword followed by a value of compatiple type is madatory for non-void returning methods. Hope to be useful. May God bless you
10th Jul 2018, 1:58 AM
Silas Junior
Silas Junior - avatar