Java methods

Introduction

Hello has been spam certified post of the previous array.

Method

-A method is a part or something like a game technique (class is like status * just my feeling). -** It doesn't work unless it is written in the {} (block) of the class **. -By using a method, when you do the same process, you only have to call it without writing the same process, so it's easy. -Easy code visibility and management.

kane.java


public static void method name() {
Process to be executed;
}

kane.java


class Main{
   public static void main(String[]args) {
    banana() ;  //()Is required.
   }

   public static void banana() {
    System.out.println("yellow") ;
   }
}

・ What is the return value? The value (data) returned from the called method to the calling method is called ** return value or return value **.

public static void main(String[] args) { }

-** When a java program is executed, it automatically starts from the main method. **. -The main method gives instructions to each method, and each supported method executes individual processing.

・ If you don't forget to write it, it's OK now.

argument

· Something like additional information given to the method. -A value can be passed from the caller when calling a method. -The value can be used even in the method passed by it.

In order to define a method that can receive arguments, specify a variable (formal argument (Karihikisu)) that will be a box for receiving arguments in the method definition part, and put the formal argument in () of public static void banana (). specify. Formal arguments, like variable definitions, ** must specify a data type **.

kane.java


class Main{
   public static void main(String[]args) {
    banana("Red") ;  
   }

   public static void banana(String color) { //Specify data type
    System.out.println("The color of this banana" + color + "is.") ;
   }
}

Even if there is no information to hand over, () is necessary, so be sure to enter it.

**-When passing multiple arguments **

kane.java


class Main{
   public static void main(String[]args) {
    banana("Philippines", 5) ;  
   }

   public static void banana(String origin, int year) { 
    System.out.println("This banana" + origin + "Of production" + year + "It's a year.") ;
   }
}

Execution result
This banana is from the Philippines for 5 years.//It's rotten

Return value

Overload

Recommended Posts

Java methods
Java methods
Java
Java
(Note) Java classes / variables / methods
[Java] Generics classes and generics methods
Check Java9 Interface private methods
Java methods and method overloads
About Java class variables class methods
Java abstract methods and classes
Java learning (0)
Studying Java ―― 3
[Java] array
Java protected
[Java] Annotation
About Java static and non-static methods
[Java] Module
Java array
Studying Java ―― 9
Java scratch scratch
Java tips, tips
Java method
java (constructor)
Java array
java (override)
java (method)
Various methods of Java String class
Java Day 2018
Java string
Java static
Java serialization
java beginner 4
JAVA paid
Studying Java ―― 4
Java (set)
[Java] compareTo
Studying Java -5
java reflexes
java (interface)
Java memorandum
☾ Java / Collection
Java array
[Java] Array
Studying Java # 0
Java review
java framework
Java features
[Java] Inheritance
FastScanner Java
Java features
java beginner 3
Java memo
Java inheritance
[Java] Overload
Java basics
[Java] Annotation
java beginner
Java (add2)
JAVA (Map)
Java9 collection
Java basics