実現したいこと
エラーの意味が分かるようになりたいです。
ですが、調べても分かりませんでした。
前提
ここに質問の内容を詳しく書いてください。
(例)
TypeScriptで●●なシステムを作っています。
■■な機能を実装中に以下のエラーメッセージが発生しました。
発生している問題・エラーメッセージ
Exception in thread "main" java.lang.Error: Unresolved compilation problem: No enclosing instance of type AreaTest is accessible. Must qualify the allocation with an enclosing instance of type AreaTest (e.g. x.new A() where x is an instance of AreaTest).
該当のソースコード
java
1public class AreaTest { 2 public static void main(String args[]) { 3 Rectangle[] rectangle = { 4 new Rectangle(8, 5), 5 new Square(5), 6 new Cube(5), 7 }; 8 for (int i = 0; i < rectangle.length; i++) { 9 System.out.println(rectangle[i].getClass().getName() + 10 ": area=" + rectangle[i].getArea()); 11 } 12 } 13 14 public class Rectangle { 15 double height; 16 double width; 17 18 public Rectangle(double height, double width) { 19 this.height = height; 20 this.width = width; 21 22 } 23 24 public double getArea() { 25 return height * width; 26 } 27 } 28 29 public class Square extends Rectangle { 30 public Square(double width) { 31 super(width, width); 32 } 33 } 34 35 public class Cube extends Square { 36 public Cube(double width) { 37 super(width); 38 } 39 40 public double getArea() { 41 return super.getArea() * 6; 42 } 43 } 44 45}
試したこと
ここに問題に対して試したことを記載してください。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2023/04/27 02:30
2023/04/27 02:44