java,作业水果,运用类的静态和重载

package wanzai;

public class Fruit {
    private static  Fruit color=null;
    private Fruit()
    {
        
    }
    public static Fruit getcolor(){
        if(color==null){
            color=new Fruit();
            
        }
        return color;
    }
    public void setcolor()
    {
        System.out.println();
    }
    public static void main(String[] args) {
        System.out.println("苹果颜色是红色");
        Fruit color1=Fruit.getcolor();
        color1.setcolor();
        System.out.println("香蕉颜色是黄色");
        Fruit color2=Fruit.getcolor();
        color2.setcolor();
    
        

}
}

package wanzai;

public class Fruit1 {
    public double price(double price){
        return price;
    }
    public int price(int weigth){
        return weigth;
    }
            
    public static void main(String[] args)
    {
        Fruit1 apple=new Fruit1();
        System.out.println("苹果的价格是"+apple.price(5.5));
        System.out.println("苹果的重量是"+apple.price(10));
        Fruit1 banana=new Fruit1();
        System.out.println("香蕉的价格是"+banana.price(4.2));
        System.out.println("香蕉的重量是"+banana.price(5));
    }
    
    }

posted @ 2016-03-08 08:14  什么玩楞啊,我叫旺仔  阅读(222)  评论(0编辑  收藏  举报