标题:求解 错误在哪
只看楼主
初学的豆豆
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2014-3-4
结帖率:100%
 问题点数:0 回复次数:1 
求解 错误在哪
public class     Vehicle{
    double speed=0;
    int power=0;
    void speedUp(int x){
        speed+=x;
    }
    void speedDown(int x){
        speed-=x;
    }
    void setPower(int x){
        power=x;
    }
    int getPower(){
        return(power);
    }
    double gerSpeed(){
        return(speed);
    }
}
public class User{
    public static void main(String args[]){
        Vehicle car1,car2;
        car1=new Vehicle();car2=new Vehicle();
        car1.setPower(128);car2.setPower(76);
        System.out.println("car1:"+car1.power);System.out.println("car2:"+car2.power);
        car1.speedUp(80);car2.speedUp(80);
        System.out.println("car1:"+car1.speed);System.out.println("car2:"+car2.speed);
        car1.speedDown(10);car2.speedDown(20);
        System.out.println("car1:"+car1.speed);System.out.println("car2:"+car2.speed);
    }
 } 错误提示 Vehicle must be defined User.java
搜索更多相关主题的帖子: double public return speed power 
2014-03-15 17:48
逆风而前
Rank: 7Rank: 7Rank: 7
来 自:福建
等 级:黑侠
威 望:7
帖 子:193
专家分:567
注 册:2013-2-14
得分:0 
class  Vehicle{
    double speed=0;
    int power=0;
    void speedUp(int x){
        speed+=x;
    }
    void speedDown(int x){
        speed-=x;
    }
    void setPower(int x){
        power=x;
    }
    int getPower(){
        return(power);
    }
    double gerSpeed(){
        return(speed);
    }
}
public class User{
    public static void main(String args[]){
        Vehicle car1,car2;
        car1=new Vehicle();car2=new Vehicle();
        car1.setPower(128);car2.setPower(76);
        System.out.println("car1:"+car1.power);System.out.println("car2:"+car2.power);
        car1.speedUp(80);car2.speedUp(80);
        System.out.println("car1:"+car1.speed);System.out.println("car2:"+car2.speed);
        car1.speedDown(10);car2.speedDown(20);
        System.out.println("car1:"+car1.speed);System.out.println("car2:"+car2.speed);
    }
}
你的文件名,应该定义为User.java
2014-03-15 21:30



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-428564-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.416552 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved