简体   繁体   English

我无法弄清楚出了什么问题,出现了“类型已定义的错误”

[英]I can't figure out what's wrong, getting a 'type already defined error'

Ok so, I'm learning java using a book I bought online, and for some reason Java wont allow this program to work even though it's the exact text from the book. 好的,我正在使用从网上购买的书来学习Java,由于某种原因,Java不允许该程序正常工作,即使它是书中的确切内容。 Can someone explain why I keep getting told 'The type SimpleCircle is already defined'? 有人可以解释为什么我不断被告知“类型SimpleCircle已经定义”吗? it shows this as an error next to the line "SimpleCircle() { radius = 1; }" 它在“ SimpleCircle(){radius = 1;}”行旁边显示为错误

public class SimpleCircle {
    /** Main method */
    public static void main(String[] args) {
        //create a circle with radius 1
        SimpleCircle circle1 = new SimpleCircle();
        System.out.println("The area of the circle of radius " 
                + circle1.radius + " is " + circle1.getArea());

        //create a a circle with radius 25
        SimpleCircle circle2 = new SimpleCircle(25);
        System.out.println("The area of the circle of radius " 
                + circle2.radius + " is " + circle2.getArea());

        //create a circle with radius 125
        SimpleCircle circle3 = new SimpleCircle(125);
        System.out.println("the area of the circle of radius " 
                + circle3.radius + " is " + circle3.getArea());

        //modify circle radius
        circle2.radius = 100;
        System.out.println("The area of the circle of radius " 
                + circle2.radius + " is " + circle2.getArea());
    }

    double radius;

    /** construct a circle with radius 1 */
    SimpleCircle() {
        radius = 1;
    }

    /** construct a circle with a specified radius */
    SimpleCircle(double newRadius) {
        radius = newRadius;
    }

    // return the area of this circle
    double getArea() {
        return radius * radius * Math.PI;
    }

    // return the perimeter of the circle
    double getPerimeter() {
        return 2 * radius * Math.PI;
    }

    // set a new radius for this circle
    void setRadius(double newRadius) {
        radius = newRadius;
    }
}

我也遇到了同样的错误,这是因为您正在使用的文件夹包含在另一个使用相同类(此处为SimpleCircle)的文件(当前工作文件除外)中,只需修改类名(例如:当前文件中的SimpleCircle到SimpleCircle2),则错误将消失。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 解析错误; 我已经尝试过,无法弄清楚出了什么问题? - Parsing error; I have tried and can't figure out what's wrong? 无法弄清楚我的DocumentFilter有什么问题 - Can't figure out what's wrong with my DocumentFilter 项目Euler#23(Java)。 我不知道怎么了。 答案是64 - Project Euler #23 (Java). I can't figure out what's wrong. Answer is off by 64 我不知道怎么了,我的逻辑似乎正确 - I can't figure out what's wrong, my logic seems correct 我无法弄清楚我的NullPointerException有什么问题或者为什么它甚至存在 - I can't figure out what's wrong with my NullPointerException or why it even exists 我无法弄清楚比较数组索引有什么问题 - I can't figure out what's wrong with comparing array indexes 我需要使用ArrayList类对数组进行排列。 我不知道怎么了 - I need to make permutations with an array using the ArrayList Class. I can't figure out what's wrong 索引超出范围异常,但无法找出问题所在 - Index out of bounds Exception but can't figure out what is wrong 我不断收到错误,我知道这可能是一个简单的错误,但为了我自己无法解决 - I keep getting an error and I know it's probably a simple mistake but I can't figure it out for the sake of me 空指针异常,我无法弄清楚我在做什么错 - Null Pointer Exception, I can't figure out what I am doing wrong
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM