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));
}
}