Когда я использую javac для компиляции нескольких .java файлов, я получаю "дублированный класс" ошибок, но я не могу найти ошибки в своем коде.
Существует четыре .java файла, все эти файлы находятся в одной папке в Windows.
- Код в MyApp.java файл:
import dx.*;
import dx.shapes.*;
class MyApp {
public static void main(String[] args) {
System.out.println("This is a test application.");
Rectangle rect = new Rectangle(10, 20);
rect.Speak();
Circle circle = new Circle(15);
circle.Speak();
Worker worker = new Worker();
worker.Speak();
}
}
Код в
Rectangle.java файл:
package dx.shapes;
public class Rectangle {
private int x, y;
private int width, height;
public Rectangle() {
this(0, 0, 1, 1);
}
public Rectangle(int width, int height) {
this(0, 0, width, height);
}
public Rectangle(int x, int y, int width, int height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
public void Speak(){
System.out.println("I'm a rectangle, width:" + this.width + ", height:" + this.height);
}
}
Код в
Circle.java Файл:
package dx.shapes;
public class Circle {
private int x, y;
private int radius;
public Circle() {
this(0, 0, 10);
}
public Circle(int radius) {
this(0, 0, radius);
}
public Circle(int x, int y, int radius) {
this.x = x;
this.y = y;
this.radius = radius;
}
public void Speak(){
System.out.println("I'm a circle, radius:" + this.radius);
}
}
Код в
Worker.java файл:
package dx;
public class Worker {
public void Speak(){
System.out.println("I'm a worker.");
}
}
В командной строке Windows я использую javac для компиляции следующих исходных кодов:
javac MyApp.java Rectangle.java Circle.java Worker.java
Но единственное, что я получил, это список ошибок:
Rectangle.java:3: error: duplicate class: dx.shapes.Rectangle
public class Rectangle {
^
MyApp.java:8: error: cannot access Rectangle
Rectangle rect = new Rectangle(10, 20);
^
bad source file: .\Rectangle.java
file does not contain class Rectangle
Please remove or make sure it appears in the correct subdirectory of the sourcepath.
Circle.java:3: error: duplicate class: dx.shapes.Circle
public class Circle {
^
MyApp.java:11: error: cannot access Circle
Circle circle = new Circle(15);
^
bad source file: .\Circle.java
file does not contain class Circle
Please remove or make sure it appears in the correct subdirectory of the sourcepath.
Worker.java:3: error: duplicate class: dx.Worker
public class Worker {
^
MyApp.java:14: error: cannot access Worker
Worker worker = new Worker();
^
bad source file: .\Worker.java
file does not contain class Worker
Please remove or make sure it appears in the correct subdirectory of the sourcepath.
6 errors
Я не знаю, что не так. Почему?