上午剛考完scjp(2002.4.25)過了84,挺美。總體感覺大部分題都挺熟,差不多有1/3原題,可能sun的題庫不大,這下美了我們這些善于考試的中國人。 平常作模擬題差不多一個小時完,今天用了100分鐘,做的特小心,怕掉井里,對不起我那幾兩銀子。 下面回憶一下題,記得不多,有幾道算幾道,希望能給后面的人提個醒兒。 1> int i=0,j=10; top: for(;;) { i++; for(;;) { if(i>--j) break top;} } 問你最后i,j是幾。(注意:i就變一次)
2> class Test { public void main(String argc[]) { System.out.println("Hello"); } } 問你輸出什么。(拋出錯誤)
3>大概是這樣 說int a=4,j=1; switch(a) case 2:j++; case 4: j++; case 1: j++; default j++; System.out.println(a+j);是多少。
4>class Foo { public static void main(String argc[]) try{ return( System.exit()); } finally{ System.out.pringln("finally"); }輸出什么。不輸出這是第一題
5>String s="blue"; String s1=s; String s="red"; System.out.println(s1);
6>String s="blue"; boolean[] bl=new boolean[1]; if (b1[0]) s="green"; 問你s最后是什么
7>硬盤當前目錄有一個文件"a.txt",里面有一些垃圾 OutputStream o = new FileOutputStream(new File("a.txt")); 然后發生了什么?a.txt變成了0字節
8>String[] a=new String[3]; int i=1; a[i]是什么?(null)
9>單選 a.GridBagLayout里面一個格子的Component either隨Frame改變大小or保持perfect size在 格子中間。 b.Frame里面BorderLayout的north位置是菜單的好位置 c.不記得了 d.不記得了 注意 a和b都是錯的,我選c
10>class a{ Integer u(){return new Integer(4);} } class b extends a{ Long u(){return new Long(8);} public static void main(String[] args){ .. } } 問結果,結果是編譯不通,override方法的返回值必須一樣
11>innter class can be static anonymous inner class can be public ............................ static ............................ privated ............................ protected 這題為A
12> ... nsigned byte i =20; ... 編譯錯誤
13>問char的范圍(不說也會吧)
14>class a{ public String toString(){ return "4" } } class b extends a{ public String toString(){ return super.toString()+"3"; } public static void main(String[] args){ System.out.println(new b()); } } 問輸出,為"43"
這題考過多次了。
15>java Test red green blue class Test{ pubic static void main(String[] args){ String k1 = args[0]; String k2 = args[1]; String k3 = args[2]; } } 問你k3是什么。blue,可能出題人喜歡藍色,好幾道題答案是這個
16>class a implements Runnable{ public void run(){ System.out.println("blue"); } } 問你如何在一個new Thread 中打印出blue 給你一些答案,你一眼就知識幾,特一賊
17> 考RandomAccessFile的構造器,問你如何向一個文件尾添加“<end>" a. ...RandomAccessFile(xxx,"a") b. .......................,"r") c. .......................,"rw") d. .......................,"w") 我選c.當時不知對不對(當時也想d了,因為是單選,看c比較熟)
18> 一個Frame, 程序里面用了setLayout(new BorderLayout());//這是蒙你的,下邊的panel是flow Panel p = new Panel(); Button b1 = new Button(); p.add(b1); add(p,北邊); Button b2 = new Button(); add(b2,南邊); .... 問你兩個button是有相同的高還是寬,frame改變大小時誰的寬不變(高,b1)
19> java.io.PrintStream p = new java.io.PrintStream( new java.io.InputStreamReader(System.out) ) 問你有不用加import xxx
thread的題考的還是那幾個,以前我看過有個網友的回憶,我這次和他的一樣,其實上面的題大部分也都一樣,認真看呦,你沒準也會碰到。下面我把那個網友的回憶的占下來。
class a implements Runnable{ private int x; private int y; public void run(){ for(;;){ x++; y++; System.out.println(" x="+x+" y="+y); System.out.println(當前Thread的名字); } } } class b{ public static void main(String[] args){ a aa = new a(); new Thread(aa).start(); new Thread(aa).start(); } }
給幾個選項,問你運行結果 非常碰巧,上面這道題改了一下又出現在我的考題里面 //前面一樣 synchronized(this){ x++; y++; } System.out.println...//后面一樣 同樣是給你幾個選項,問運行結果 這個是同步的,上面那個有可能輸出x!=y的結果,這個就不會了 大家要注意5,6都只有一個aa,也就是不會出現相同的x或y.
還有一個很經典的thread題,也是真題, Thread1 synchronized(a){ synchronized(b){ } } Thread2 synchronized(b){synchronized(a){ } } 都start();問結果,結果是 可能deadlock,就是大家很常見的那道題 a,b是StringBuffer();Thread1,2是用 new Thread(){ public void run(){ //.... } }.start(); 方式定義 一字不變 (我這題可能錯了,當時我記得論壇里說過的,答案忘了,我肯定下次還有這個)
對了還有,前天還在論壇里說呢
which two declaretions provent the overriding of a method? a final void methoda(){} b void final methoda(){} c static void methoda(){} d static final void methoda(){} e final abstract void methoda(){}
答案現在我也不敢定,有人說(書上)是a,d.可一個是static 一個是non-static呀 我在機器試著a,d不成。我說是c,d.只要是c在前,d在后就成(試過)
還有:問鼠標移動要實現那個接口(明白人知道我再說什么吧),key pressed要那個接口,倆題。
垃圾回收問你第幾行那個(就是好多模擬是都有的那個,在第7行后)
有一個考數學函數的題忘了,答案是int a=(int)round(double b)
還有hashtable繼承的那個接口。(map) 問你有這種形式的什么key-values,選兩個(map,sortedmap)
提問:能讓進程停止的選兩個 a.wait(); b.notify(); c.notifyall(); d.退出synchronized black e.call setPriority(); 這題我可能錯了(a,d)
得到父目錄的方法是什么,自己找吧。
還有一個,最后一個了只能回憶這么多了(內存有限)。 class a { class inerexception extends Exception{} void trytest() throws inerexception{}; void test() //xxxxxxxx { trytest(); }
}
xxxxxx有什么代替 a.throws Exception b.catch(....) c.throw inerexception d.throws inerexception e.好像還有一catch的 答案 a
總之,上面這些題在mock test中大多有涉及,我發現網上的朋友真無私,提供那么多不用銀子的mock test.我太感動了流淚了:)..。從對java一點不會到今天考完,仨月,長了點(我笨),可能有人不用一月就搞定,我對E文很反感,所以就看了張洪斌那本書。挺有針對性的。接下來就是作題,1000多道吧,如有誰想要說話hansonxjy@21cn.com,我希望考的人都過,畢竟大家掙的都是辛苦錢。(完)
|