2022年3月20日解決済み

なぜ User クラスを作る必要があるのですか?

ユーザー

class User と public class MyApp の2つがありますが、以下のように MyApp のクラスに "Me!" と "hi!" を記載してはいけないのですか?

public class MyApp {

    public static void main(String[] args) {
    String name = "Me!"; // フィールド

    void sayHi() {
       System.out.println("hi!");
     }
      User tom;
      tom = new User(); // インスタンス
      System.out.println(tom.name);
      tom.sayHi();
    }
}
スタッフ

この回答を見るにはプレミアムプランへの登録が必要です

プレミアムプランとは?