错误:在课程中找不到主要方法

时间:2016-10-22 13:55:49

标签: java class methods main

以前在网站上已经提出过这个问题,但我无法弄清楚出了什么问题。我从Oracle教程中复制并粘贴,它仍然给出了错误消息:

错误:在类bike.Bicycle中找不到主要方法,请将main方法定义为:    public static void main(String [] args) 或者JavaFX应用程序类必须扩展javafx.application.Application C:\ Users \ Junaid \ AppData \ Local \ NetBeans \ Cache \ 8.2 \ executor-snippets \ run.xml:53:Java返回:1 BUILD FAILED(总时间:0秒)

http://docs.oracle.com/javase/tutorial/java/concepts/class.html

    package bicycle;


    class Bicycle{

int cadence = 0;
int speed = 0;
int gear = 1;

void changeCadence(int newValue) {
     cadence = newValue;
}

void changeGear(int newValue) {
     gear = newValue;
}

void speedUp(int increment) {
     speed = speed + increment;   
}

void applyBrakes(int decrement) {
     speed = speed - decrement;
}

void printStates() {
     System.out.println("cadence:" +
         cadence + " speed:" + 
         speed + " gear:" + gear);
}
    }

    class BicycleDemo {
        public static void main(String[] args) {
    // Create two different 
    // Bicycle objects
    Bicycle bike1 = new Bicycle();
    Bicycle bike2 = new Bicycle();

    // Invoke methods on 
    // those objects
    bike1.changeCadence(50);
    bike1.speedUp(10);
    bike1.changeGear(2);
    bike1.printStates();

    bike2.changeCadence(50);
    bike2.speedUp(10);
    bike2.changeGear(2);
    bike2.changeCadence(40);
    bike2.speedUp(10);
    bike2.changeGear(3);
    bike2.printStates();
}
}

0 个答案:

没有答案