我试图获得与汽车编译器一起运行的帮助,我改变了几件事,发现了1个错误

public class AutomobileDescription
{
    /**
    Constructor to display the make, model and price the new automobile I wish to purchase
   */

    public AutomobileDescription(String carMake, String carModel, carPrice)
    {
        make = m;
        model = mo;
        price = p;
    }
     public String m =("Toyota");
     public String mo =("Camry");
     public String p =("22055");

     public String getAutomobileinfo()
     {
     return m + mo +  p;
     Automobile myAutomobile = new Automobile(Toyota, Camry, 22055);
     System.out.println("The Make, Model and Price of the car is: m + mo + p ");

    }
}


---- jGRASP执行:javac -g AutomobileDescription.java

AutomobileDescription.java:7:错误:预期
    公共汽车描述(车串制造,车模型,车价)
                                                                          ^
1个错误

---- jGRASP楔2:进程的退出代码为1。
 ---- jGRASP:操作完成。

最佳答案

您在这里遇到多个问题:

public class AutomobileDescription
{
    /**
    Constructor to display the make, model and price the new automobile I wish to purchase
   */

public AutomobileDescription(String carMake, String carModel, /*no return type*/ carPrice)
{
    make = m;
    model = mo;
    price = p;
}
 public String m =("Toyota");
 public String mo =("Camry");
 public String p =("22055");

    public String getAutomobileinfo()
    {
     return m + mo +  p; /*return? then why statements after this?*/
     Automobile myAutomobile = new Automobile(Toyota, Camry, 22055);
     System.out.println("The Make, Model and Price of the car is: m + mo + p ");

    }
}


解:

public class AutomobileDescription{
/**
Constructor to display the make, model and price the new automobile I wish to purchase
*/

public AutomobileDescription(String carMake, String carModel, String carPrice)
{
    m = make;
    mo = model;
    p = carPrice;
}
 private String m;
 private String mo;
 private String p;

 public String getAutomobileinfo()
 {
    return m + mo +  p;
 }
 public static void main(String[] args){
    AutomobileDescription myAutomobile = new AutomobileDescription("Toyota", "Camry", "22055");
    System.out.println("The Make, Model and Price of the car is: " + myAutomobile.getAutomobileinfo());
 }
}

关于java - 尝试实现一个类,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14669513/

10-13 06:25