Building Java Programs: A Back to Basics Approach (4th Edition)
Building Java Programs: A Back to Basics Approach (4th Edition)
4th Edition
ISBN: 9780134322766
Author: Stuart Reges, Marty Stepp
Publisher: PEARSON
bartleby

Videos

Question
Book Icon
Chapter 1.4, Problem 21SCP
Program Plan Intro

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.

Blurred answer
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
CPP Function Parameters | Returning Values from Functions | C++ Video Tutorial; Author: LearningLad;https://www.youtube.com/watch?v=WqukJuBnLQU;License: Standard YouTube License, CC-BY