为什么public修饰类之后编译失败?代码内容不重要,问题在于public- public class TestB63
- {
- public static void main(String[] args)
- {
- Clothing ct = new Clothing(200,1,"男装");
- ct.show();
- }
- }
- //服装类
- public class Clothing extends Goods implements VipPrice
- {
- String style;
- Clothing(double unitPrice,int count,String style)
- {
- super(unitPrice,count);
- this.style=style;
- }
- public double reducedPrice()
- {
- return VipPrice.DISCOUNT*unitPrice;
- }
- public void show()
- {
- System.out.println("服装单价:"+getUnitPrice());
- System.out.println("数量:"+getAccount());
- System.out.println("样式:"+style);
- System.out.println("总价:"+totalPrice());
- System.out.println("VIP价格:"+reducedPrice());
- }
- }
- //VIP
- public interface VipPrice
- {
- double DISCOUNT=0.85;
- double reducedPrice();
- }
- //商品
- public class Goods
- {
- double unitPrice;
- int count;
- Goods(double unitPrice,int count)
- {
- this.unitPrice=unitPrice;
- this.count=count;
- }
- public double totalPrice()
- {
- double price=unitPrice*count;
- return price;
- }
- public int getAccount()
- {
- return count;
- }
- public double getUnitPrice()
- {
- return unitPrice;
- }
- }
复制代码
|
|