实现代码很简单: package com.xiaozan.shopping; import java.util.Arrays; public class ShoppingCart { public final static int PRODUCT_1_PRICE = 2000; // 产品编号第一个数字为1的单价,单位(分) public final static int PRODUCT_2_PRICE = 1000; // 其他产品编号的单价,…
1. 静态工厂方法 静态工厂方法不必在每次调用它们的时候都创建一个新的对象: Boolean.valueOf(boolean): public final class Boolean { public static final Boolean TRUE = new Boolean(true); public static final Boolean FALSE = new Boolean(false); public static Boolean valueOf(boolean b) { ret…
实现代码很简单: package com.xiaozan.shopping; import java.util.Arrays; public class ShoppingCart { public final static int PRODUCT_1_PRICE = 2000; // 产品编号第一个数字为1的单价,单位(分) public final static int PRODUCT_2_PRICE = 1000; // 其他产品编号的单价,…
面试官Q1:请问String s = new String("xyz");产生了几个对象? 对于这个Java面试题,老套路先上代码: public class StringTest { public static void main(String[] args){ String s1="Hello"; String s2="Hello"; String s3=new String("Hello"); System.out.pr…
JAVA代码查错 1. abstract class Name { private String name; public abstract boolean isStupidName(String name) {} } 大侠们,这有何错误? 答案: 错.abstract method必须以分号结尾,且不带花括号. 2. public class Something { void doSomething () { private String s = ""; int l = s.leng…