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

例を出しながら説明していきます。
2022年3月12日
ユーザー

class Userpublic 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();
    }
}

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

プレミアムプランとは?