我需要一個受保護的變量添加到產品類文件添加一個受保護的變量(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