我需要一个受保护的变量添加到产品类文件添加一个受保护的变量(i附上该文件的当前代码),我有。我需要将计数变量的访问修饰符从public更改为protected。 我该怎么做?!我需要什么样的变化的代码,使下面添加一个受保护的变量:如何用Java
import java.text.NumberFormat;
public class Product
{
private String code;
private String description;
private double price;
public static int count = 0;
public Product()
{
code = "";
description = "";
price = 0;
}
public void setCode(String code)
{
this.code = code;
}
public String getCode(){
return code;
}
public void setDescription(String description)
{
this.description = description;
}
public String getDescription()
{
return description;
}
public void setPrice(double price)
{
this.price = price;
}
public double getPrice()
{
return price;
}
public String getFormattedPrice()
{
NumberFormat currency = NumberFormat.getCurrencyInstance();
return currency.format(price);
}
@Override
public String toString()
{
return "Code: " + code + "\n" +
"Description: " + description + "\n" +
"Price: " + this.getFormattedPrice() + "\n";
}
public static int getCount()
{
return count;
}
}
这是你的作业吗? – Chakra 2012-07-23 05:09:15