explain java methods with syntax and examples
Answers
Answered by
3
Sudha is currently an Information Technology Specialist and a EdD student at the University of Delaware.
Java programs have methods that have a name and contain a set of statements or instructions. In this lesson, we'll learn how the Java programming language uses methods and the rules and syntax we need to employ when using them.
What Is a Method in Java?
In the Java programming language, a method is a section of the program that contains a set of instructions or code. In a Java program, similar to a cake recipe, a method has a set of instructions. When the method is called, the set of instructions within the method is executed.

Here, the name of the method is addNumbers. When the method addNumbers is called, the code within the method is executed, and the variable z is printed.
Parameters of a Method
When following the method to make cake, the ingredients like sugar and butter are combined and processed to make the final product. Similarly, Java methods have parameters (like ingredients) or data that are inputted or passed into the method. The method uses these parameter values to do the necessary data manipulation and processing. The method then usually returns the final value after all the necessary data processing is successfully performed.

In this example, m and n are parameters. The Java method subtractNumbers finds the difference between m and n and saves the result in a new variable p. The values of the parameters m and n are used to generate the new variable p that is printed out on the computer screen.
The parameters of a method are declared within parentheses following the method name. If there is more than one parameter, they are separated by commas. Both the data type and the variable name (int m, int n) are specified for the parameters
Java programs have methods that have a name and contain a set of statements or instructions. In this lesson, we'll learn how the Java programming language uses methods and the rules and syntax we need to employ when using them.
What Is a Method in Java?
In the Java programming language, a method is a section of the program that contains a set of instructions or code. In a Java program, similar to a cake recipe, a method has a set of instructions. When the method is called, the set of instructions within the method is executed.

Here, the name of the method is addNumbers. When the method addNumbers is called, the code within the method is executed, and the variable z is printed.
Parameters of a Method
When following the method to make cake, the ingredients like sugar and butter are combined and processed to make the final product. Similarly, Java methods have parameters (like ingredients) or data that are inputted or passed into the method. The method uses these parameter values to do the necessary data manipulation and processing. The method then usually returns the final value after all the necessary data processing is successfully performed.

In this example, m and n are parameters. The Java method subtractNumbers finds the difference between m and n and saves the result in a new variable p. The values of the parameters m and n are used to generate the new variable p that is printed out on the computer screen.
The parameters of a method are declared within parentheses following the method name. If there is more than one parameter, they are separated by commas. Both the data type and the variable name (int m, int n) are specified for the parameters
Answered by
2
mujhe is question ka ans nahi malum h par me chata hu ki tu mere is reply Ko brainliest mark kare kyu ki Mene ye tuje personally sikhaya h . isileye me is par tujhe iska and nahi du ga Patel.
- DHEERAV NAHAR
- DHEERAV NAHAR
akshatpatel070pamv82:
muje kya milega tuje brainleast mark karke
Similar questions
Science,
9 months ago
Math,
9 months ago
Science,
9 months ago
English,
1 year ago
Environmental Sciences,
1 year ago