java
1package main; 2 3public class Main { 4 5 public class Person { 6 String name; 7 8 public Person() { 9 10 } 11 12 public Person(String name) { 13 this.name = name; 14 } 15 16 public void disp() { 17 System.out.println("The name is " + name); 18 } 19 20 } 21 public class Engineer extends Person{ 22 String field; 23 24 public Engineer() { 25 26 } 27 public Engineer(String field) { 28 this.field = field; 29 } 30 31 public void disp() { 32 System.out.println("The field is " + name); 33 } 34 35 } 36 public static void main(String[] args) { 37 Person person = new Person(); 38 39 } 40}
コンパイルエラーで
error
1アクセス可能な型 Main のエンクロージング・インスタンスがありません。型 Main のエンクロージング・インスタンスで割り振りを限定する必要があります (たとえば x.new A() で、x は Main のインスタンス)。
が出ます。
どう記述すれば良いでしょうか。
条件は満たしている気がするのですが。
https://teratail.com/help/question-tips#questionTips3-1
あと、このくらい本当に基礎で調べれば解決するので質問作ってる間に調べた方がいいです。過去質問にもあるんじゃないですか?

回答3件
あなたの回答
tips
プレビュー