【发布时间】:2017-11-29 03:24:44
【问题描述】:
我是 Java 的初学者,我正在做一个课程项目。我还发现 Java 很难掌握,而且我遇到了这个编译错误的问题。这只是 1 个错误,让我更加困惑,因为当我在其他地方使用该变量时我没有得到一个。
* 错误 *
文件:D:\Programming\Project 2\Product.java [行:47]
错误:newCompType 无法解析为变量
public class Product
{
//Instance variables
private String name; //Name of Product
private String compType; //Type of Product
private double price; //Price of Product
private int quantity; //How many computers
//Constructors
public Product()
{
name = "Dell";
compType = "Laptop";
price = 200;
quantity = 1;
}
public Product(String newName, String newCompType, double newPrice, int newQuantity)
{
name = newName;
compType = newCompType;
price = newPrice;
quantity = newQuantity;
}
//Instance methods
public void printData()
{
System.out.println("Name of computer: " + name);
System.out.println("Type of computer: " + compType);
System.out.println("Number of computers: " + quantity);
System.out.println("Cost of computer: " + price);
}
public void setName(String newName)
{
name = newName;
}
public String getName()
{
return name;
}
public void setCompType(String setCompType)
{
compType = newCompType;
}
public String getCompType()
{
return compType;
}
public void setPrice(double newPrice)
{
price = newPrice;
}
public double getPrice()
{
return price;
}
public void setQuantity(int newQuantity)
{
quantity = newQuantity;
}
public int getQuantity()
{
return quantity;
}
public String toString(){
return name + " " + compType + " " + quantity + " " + price + "\n";
}
}
【问题讨论】:
-
因此请阅读指定行的代码,看看是否无法发现问题。很清楚——差点跳出来打你的鼻子。
标签: java compiler-errors