0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

クラス、メソッドの呼び出し方

Last updated at Posted at 2020-01-20

Foodクラスのfruitsメソッド(Food.java)

Food.java
public class Food {
  // 以下のメソッドすべてを、Personクラスに移動してください

  public static String fruits(String fruitsName) {
    return fruitName;
  }

Mainクラスのmainメソッド(main.java)

Food.java内にあるFoodクラスのfruitsメソッドを呼び出し。

Main.java
public class Main {
  public static void main(String[] args) {

    Food.printData(Food.fruits("apple"));
    Food.printData(Food.fruits("straeberry", "Smith"), 65, 1.75, 80.0);
  }
}

別のクラスのメソッドを呼び出すときは、クラス名、メソッド名の前にそれぞれ、呼び出したいクラスの名前を書く必要有。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?