質問するログイン新規登録

質問編集履歴

1

マークダウンに記述

2020/05/03 02:44

投稿

hiro.a
hiro.a

スコア28

title CHANGED
File without changes
body CHANGED
@@ -5,41 +5,20 @@
5
5
  ### 発生している問題・エラーメッセージ
6
6
 
7
7
  Rect クラスへのアクセスがエラーとなっている
8
- ```
9
8
  エラーメッセージ
10
9
 
11
10
  Exception in thread "main" java.lang.IllegalAccessError: failed to access class Rect from class IfSample3 (Rect is in unnamed module of loader 'app'; IfSample3 is in unnamed module of loader com.sun.tools.javac.launcher.Main$MemoryClassLoader @16022d9d)
12
11
  at IfSample3.main(IfSample3.java:4)
13
12
 
14
- ### 該当のソースコード
15
13
 
16
- class IfSample3 {
17
- public static void main(String[] args){
18
-
19
- Shape s1 = new Rect(10.0, 5.0);
20
- showArea(s1);
21
-
22
- Shape s2 = new Circle(3.0);
23
- showArea(s2);
24
- }
25
-
26
- static void showArea(Shape shape){
27
- System.out.println(shape.getArea());
28
-
29
- }
30
- }
31
-
32
-
33
- ```Java
14
+ ```java
34
- //Shape.java
35
-
36
15
  interface Shape{
37
16
  public double getArea();//面積を計算して返す抽象メソッド(シグネチャのみ定義)
38
17
 
39
18
  }
40
19
 
41
-
20
+ ```
42
- ```//Rect.java
21
+ ```java
43
22
  class Rect implements Shape{//Shapeを実装
44
23
 
45
24
  double width;
@@ -54,8 +33,9 @@
54
33
 
55
34
  }
56
35
  }
36
+ ```
57
37
 
58
- ```//Circle.java
38
+ ```java
59
39
  class Circle implements Shape{
60
40
  double radius;
61
41
 
@@ -67,7 +47,29 @@
67
47
  return radius * radius * 3.14 ;
68
48
  }
69
49
  }
50
+ ```
70
51
 
52
+ ```java
53
+ class IfSample3 {
54
+ public static void main(String[] args){
55
+
56
+ Shape s1 = new Rect(10.0, 5.0);
57
+ showArea(s1);
58
+
59
+ Shape s2 = new Circle(3.0);
60
+ showArea(s2);
61
+ }
62
+
63
+ static void showArea(Shape shape){
64
+ System.out.println(shape.getArea());
65
+
66
+ }
67
+ }
68
+ ```
69
+
70
+
71
+
72
+
71
73
  ### 試したこと
72
74
 
73
75
  IfSample3のjava:4がエラーの表示が出ているのでスペルミスがないか確認