Home > Java > javaTutorial > body text

Post Understanding Methods in Java

Linda Hamilton
Release: 2024-10-02 11:35:03
Original
743 people have browsed it

A method is a block of code that performs a specific task.
Structure of the Method

public returnType methodName(parameterType parameterName) {
// Method body (code to be executed)
}

Let's break down this

  • public: public is the Access Modifier. Whether you want to show it to the other or not. So here 'public' means that you want to show it to others. There are different types of Access Modifiers e.g., public, private, protected.

  • returnType: It is what the method will return. If the method does not return anything then you type void.

  • methodName: This is the name you give to the method, which should be descriptive of what the method does.

Post Understanding Methods in Java

In method 3("named as multiply") we assign the parameters in the parentheses after the method name because we want input from the users.

The above is the detailed content of Post Understanding Methods in Java. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!