纯手打,有些字删减了,大家权当乐呵乐呵。
代码直接复制就可以跑的,尽量跑跑看结果跟自己想的一样不一样吧。
[list]
B. java.util.Arrays: asList(T... a)
C. java.util.Properties: loadFromXML(InputStream in)
D. java.util.Collections binarySearch()
List<String> list = new ArrayList<String>(); list.add("A"); list.add("B"); list.add("C"); for(String s : list){ if(s.equals("A")){ list.add("E"); } }
B.都允许null键值
C.前者同步后者不
D.Collection视图方法都是快速失败的(这个选项根本没看懂。。。)
E.都可以自定义容量和加载因子
B.一个类只能继承一个抽象类
C.抽象类可以提供实现
D.接口可以私有成员变量
public class FakeThread extends Thread { private String name; public static void main(String[] args) { FakeThread t = new FakeThread(); t.go(); } public FakeThread() { } public FakeThread(String name) { this.name = name; } public String getThreadName() { return name; } private void go() { FakeThread first = new FakeThread("first"); first.start(); FakeThread second = new FakeThread("second"); second.start(); } public void start() { for (int i = 0; i < 2; i++) { System.out.println(this.getThreadName() + i); try { Thread.sleep(100); } catch (Throwable e) { e.printStackTrace(); } } } }
StringBuffer sb = new StringBuffer("abc"); String s = new String("abc"); sb.append("def"); s.append("def"); sb.insert(1, "zzz"); s.concat(sb); s.trim();
public class Null { public static void greet() { System.out.println("Hello World"); } @SuppressWarnings("static-access") public static void main(String[] args) { ((Null) null).greet(); } }
public class Twisted { private final String name; Twisted(String name) { this.name = name; } private String name() { return name; } private void reproduce() { new Twisted("reproduce") { public void printName() { System.out.println(name()); } }.printName(); } public static void main(String[] args) { new Twisted("main").reproduce(); } }
public class StaticClassNField { public static void main(String[] args) { System.out.println(X.Y.Z); } } class X { static class Y { static String Z = "Black"; } static C Y = new C(); } class C { String Z = "White"; }
public class DatingGame { public static void main(String[ ] args) { Calendar cal = Calendar.getInstance(); cal.set(1999, 12, 31); // Year, Month, Day System.out.print(cal.get(Calendar.YEAR) + " "); Date d = cal.getTime(); System.out.println(d.getDay()); } }
[/list]
感觉有点长了,先搞到这里。后面还有几题回头补充。
突然 发现有种高中时候做卷子的感觉。。。