Syntax of java method:
Modifier static returnType nameofMethod (Parameter List)
{
//method body
}
In the above syntax,
Modifier:
The modifier defines access type, whether the method is public, private or protected.
Static:
If the user put “static” keyword in a method, then it becomes a static method. The use of static method is it can be called without creating instance of a class.
For example, consider the “sqrt()” method of “Math” class and it is defined as static. Hence, the user can access it directly by calling “Math.sqrt()” without creating an instance of “Math” class.
returnType:
A java method can return a value. The method can return data of type, “int”, “float”, “double”, “String” and so on. If the method does not have any value to return, the return type should be “void”.
nameOfMethod:
The name for a method is an identifier. The user can give any name to the method. But it is good to give the names that related to the task it perform. For example, “calculateArea”, “calculateSum” and so on.
Parameters:
The values passed to the method are the parameters. The user can pass any number of parameters.
Method body:
The body of a method defines the tasks performed by the method. It defines, how the parameters are manipulated and what type of values is returned.
Want to see the full answer?
Check out a sample textbook solutionChapter 1 Solutions
Building Java Programs: A Back To Basics Approach, Loose Leaf Edition (5th Edition)
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education