- public class Problems {
- public static void main(String[] args) {
- System.out.println(Price.INSTANCE.currentPrice);
- Price price=new Price(2.8);
- System.out.println(price.currentPrice);
- }
- }
- class Price{
- static Price INSTANCE = new Price(2.8);
- static double initPrice = 20;
- double currentPrice;
- public Price(double discount){
- currentPrice = initPrice - discount;
- }
- }
- /*运行结果:-2.8
- * 17.2
- */
复制代码 |