JAVA基礎(chǔ)部分面試千題庫(kù)_第1頁(yè)
JAVA基礎(chǔ)部分面試千題庫(kù)_第2頁(yè)
JAVA基礎(chǔ)部分面試千題庫(kù)_第3頁(yè)
JAVA基礎(chǔ)部分面試千題庫(kù)_第4頁(yè)
JAVA基礎(chǔ)部分面試千題庫(kù)_第5頁(yè)
已閱讀5頁(yè),還剩325頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、java基礎(chǔ)部分面試題庫(kù)第一部分:選擇題1)哪個(gè)不是面向?qū)ο蟮奶卣?( )a)封裝性b)繼承性c)多態(tài)性d)健壯性2)編譯java文件的命令是( )。a)javab)javacc)javadbd)javaw3)java源文件的擴(kuò)展名是( )。a)classb)exec)java d)dll4)java內(nèi)部使用的編碼格式是( )。a)utf-8b)asciic)unicoded)iso8859-15)下列變量名稱不合法的是( )a)indexb)$bc3&c)_cccded)34#bc56)下邊對(duì)基本數(shù)據(jù)類型的說(shuō)明正確的是( )a)int可以自動(dòng)轉(zhuǎn)換為byte類型b)double類型的數(shù)據(jù)占用2

2、個(gè)字節(jié)c)java中一共有4類8種基本數(shù)據(jù)類型d)java中一共有3類8種基本數(shù)據(jù)類型7)下列不是java關(guān)鍵字的是( )a)gotob)ifc)countd)private8)下列變量聲明中正確的是( )a)float f = 3.13 b)boolean b = 0c)int number = 5d)int x byte a = 9)public void go() string o = ; z: for(int x = 0; x 3; x+) for(int y = 0; y 2; y+) if(x=1) break; if(x=2 & y=1) break z; o = o + x +

3、 y; system.out.println(o); 程序的執(zhí)行結(jié)果是( )a)00b)0001c)000120d)00012021e)compilation fails.f)an exception is thrown at runtime10)class payload private int weight; public payload (int w) weight = w; public void setweight(int w) weight = w; public string tostring() return integer.tostring(weight); public c

4、lass testpayload static void changepayload(payload p) /* insert code */ public static void main(string args) payload p = new payload(200); p.setweight(1024); changepayload(p); system.out.println(p is + p); insert code處寫入哪句話, 可以使程序的輸出結(jié)果是420( )a)p.setweight(420);b)p.changepayload(420);c)p = new payloa

5、d(420);d)payload.setweight(420);e)p = payload.setweight(420);11)void waitforsignal() object obj = new object(); synchronized (thread.currentthread() obj.wait(); obj.notify(); 這個(gè)程序片段的運(yùn)行結(jié)果是什么( )a)this code can throw an interruptedexception.b)this code can throw an illegalmonitorstateexception.c)this c

6、ode can throw a timeoutexception after ten minutes.d)reversing the order of obj.wait() and obj.notify() might cause this method to complete normally.12)public class threads2 implements runnable public void run() system.out.println(run.); throw new runtimeexception(problem); public static void main(s

7、tring args) thread t = new thread(new threads2(); t.start(); system.out.println(end of method.); 運(yùn)行結(jié)果是什么,請(qǐng)選擇2個(gè)( )a)java.lang.runtimeexception: problemb)run. java.lang.runtimeexception: problemc)end of method. java.lang.runtimeexception: problemd)end of method. run. java.lang.runtimeexception: proble

8、me)run. java.lang.runtimeexception: problem end of method.13)下邊哪2句話的描述是正確的( )a)it is possible for more than two threads to deadlock at onceb)the jvm implementation guarantees that multiple threads cannot enter into a deadlocked state.c)deadlocked threads release once their sleep() methods sleep dura

9、tion has expired.d)deadlocking can occur only when the wait(), notify(), and notifyall() methods are used incorrectly.e)it is possible for a single-threaded application to deadlock if synchronized blocks are used incorrectly.f)f a piece of code is capable of deadlocking, you cannot eliminate the pos

10、sibility of deadlocking by inserting invocations of thread.yield().14)public class threads2 implements runnable public void run() system.out.println(run.); throw new runtimeexception(problem); public static void main(string args) thread t = new thread(new threads2(); t.start(); system.out.println(en

11、d of method.); 程序運(yùn)行結(jié)果是,選擇2個(gè)( )a)java.lang.runtimeexception: problem b)run. java.lang.runtimeexception: problem end of methodc)end of method. java.lang.runtimeexception: problemd)end of method. run. java.lang.runtimeexception: problem15) void waitforsignal() object obj = new object(); synchronized (t

12、hread.currentthread() obj.wait(); obj.notify(); 下列那句描述是正確的( )a)this code can throw an interruptedexception.b)this code can throw an illegalmonitorstateexception.c)this code can throw a timeoutexception after ten minutes.d)this code does not compile unless obj.wait() is replaced with (thread) obj).wa

13、it().16)11. class pingpong2 synchronized void hit(long n) for(int i = 1; i 3; i+) system.out.print(n + - + i + ); public class tester implements runnable static pingpong2 pp2 = new pingpong2(); public static void main(string args) new thread(new tester().start(); new thread(new tester().start(); . p

14、ublic void run() pp2.hit(thread.currentthread().getid(); 運(yùn)行結(jié)果是( )a)the output could be 5-1 6-1 6-2 5-2b)the output could be 6-1 6-2 5-1 5-2c)the output could be 6-1 5-2 6-2 5-1d)the output could be 6-1 6-2 5-1 7-117)1. public class threads4 public static void main (string args) new threads4().go();

15、public void go() runnable r = new runnable() public void run() system.out.print(foo); ; thread t = new thread(r); t.start(); t.start(); 運(yùn)行結(jié)果是( )a)compilation fails.b)an exception is thrown at runtime.c)the code executes normally and prints foo.d)the code executes normally, but nothing is printed.18)

16、11. public class barn public static void main(string args) new barn().go(hi, 1); new barn().go(hi, world, 2); public void go(string. y, int x) system.out.print(yy.length - 1 + ); 運(yùn)行結(jié)果是( )a)hi hib)hi worldc)compilation failsd)an exception is thrown at runtime.19)10. class nav . public enum direction

17、north, south, east, west public class sprite / insert code here 哪句代碼放到14行,程序可以正常編譯( )a)direction d = north;b)nav.direction d = north;c)direction d = direction.north;d)nav.direction d = nav.direction.north;20)11. public class rainbow public enum mycolor red(0xff0000), green(0x00ff00), blue(0x0000ff);

18、 private final int rgb; mycolor(int rgb) this.rgb = rgb; public int getrgb() return rgb; ; public static void main(string args) / insert code here 哪句代碼放到19行,程序可以正常編譯( ) a)mycolor skycolor = blue;b)mycolor treecolor = mycolor.green;c)compilation fails due to other error(s) in the code.d)mycolor purpl

19、e = mycolor.blue + mycolor.red;21)5. class atom atom() system.out.print(atom ); class rock extends atom rock(string type) system.out.print(type); public class mountain extends rock mountain() super(granite ); new rock(granite ); public static void main(string a) new mountain(); 運(yùn)行結(jié)果是( )a)compilation

20、 failsb)atom granite granitec)an exception is thrown at runtime.d)atom granite atom granite22)1. interface testa string tostring(); public class test public static void main(string args) 4system.out.println(new testa() public string tostring() return test; 運(yùn)行結(jié)果是( )a)testb)nullc)an exception is throw

21、n at runtime.d)compilation fails because of an error in line 1.23)11. public static void parse(string str) try float f = float.parsefloat(str); catch (numberformatexception nfe) f = 0; finally 17. system.out.println(f); public static void main(string args) parse(invalid); 運(yùn)行結(jié)果是( )a)0.0b)compilation

22、fails.c)a parseexception is thrown by the parse method at runtimed)a numberformatexception is thrown by the parse method at runtime24)1. public class blip protected int blipvert(int x) return 0; class vert extends blip / insert code here 下列哪5個(gè)方法放到代碼第五行,可以讓程序編譯正確,選擇5個(gè)( )a)public int blipvert(int x) r

23、eturn 0; b)private int blipvert(int x) return 0; c)private int blipvert(long x) return 0; d)protected long blipvert(int x) return 0; e)protected int blipvert(long x) return 0; f)protected long blipvert(long x) return 0; g)protected long blipvert(int x, int y) return 0; 25)1. class super private int

24、a; protected super(int a) this.a = a; . class sub extends super public sub(int a) super(a); public sub() this.a = 5; 下列哪2條語(yǔ)句是正確的( )a)change line 2 to: public int a;b)change line 2 to: protected int a;c)change line 13 to: public sub() this(5); d)change line 13 to: public sub() super(5); e)change line

25、 13 to: public sub() super(a); 26) package test; class target public string name = hello; 如果可以直接修改和訪問(wèn)name這個(gè)變量,下列哪句話是正確的a)any classb)only the target classc)any class in the test packaged)any class that extends target27)11. abstract class vehicle public int speed() return 0; class car extends vehicle

26、public int speed() return 60; class racecar extends car public int speed() return 150; . racecar racer = new racecar(); car car = new racecar(); vehicle vehicle = new racecar(); system.out.println(racer.speed() + , + car.speed() + , + vehicle.speed();運(yùn)行結(jié)果是( )a)0, 0, 0b)150, 60, 0c)compilation failsd

27、)150, 150, 150e)an exception is thrown at runtime28)5. class building public class barn extends building public static void main(string args) building build1 = new building(); barn barn1 = new barn(); barn barn2 = (barn) build1; object obj1 = (object) build1; string str1 = (string) build1; building

28、build2 = (building) barn1; 15. 運(yùn)行結(jié)果是( )a)if line 10 is removed, the compilation succeeds.b)if line 11 is removed, the compilation succeedsc)if line 12 is removed, the compilation succeeds.d)if line 13 is removed, the compilation succeeds.e)more than one line must be removed for compilation to succee

29、d.29)29.given: class money private string country = canada; public string getc() return country; class yen extends money public string getc() return super.country; public class euro extends money public string getc(int x) return super.getc(); public static void main(string args) system.out.print(new

30、 yen().getc() + + new euro().getc(); 33. 運(yùn)行結(jié)果是( )a)canadab)null canadac)canada nulld)compilation fails due to an error on line 26e)compilation fails due to an error on line 2930)13. import java.io.*; class food implements serializable int good = 3; class fruit extends food int juice = 5; public clas

31、s banana extends fruit int yellow = 4; public static void main(string args) banana b = new banana(); banana b2 = new banana(); b.serializebanana(b); / assume correct serialization b2 = b.deserializebanana(); / assume correct system.out.println(restore +b2.yellow+ b2.juice+b2.good); / more banana met

32、hods go here 運(yùn)行結(jié)果是( )a)restore 400b)restore 403c)restore 453d)compilation fails.e)an exception is thrown at runtime.31)11. double input = 314159.26; numberformat nf = numberformat.getinstance(locale.italian); string b; /insert code here下列哪條語(yǔ)句可以設(shè)置變量b的值為314.159,26( )a).b = nf.parse( input );b)b = nf.f

33、ormat( input );c)b = nf.equals( input );d)b = nf.parseobject( input );32)1. public class teststring1 public static void main(string args) string str = 420; str += 42; system.out.print(str); 7. 輸出結(jié)果是( )a)42b)420c)462d)4204233)22. stringbuilder sb1 = new stringbuilder(123); string s1 = 123; / insert c

34、ode here system.out.println(sb1 + + s1);下列哪句代碼放到程序的第24行,可以輸出123abc 123abc( )a)sb1.append(abc); s1.append(abc);b)sb1.append(abc); s1.concat(abc);c)sb1.concat(abc); s1.append(abc);d)sb1.concat(abc); s1.concat(abc);e)sb1.append(abc); s1 = s1.concat(abc);f)sb1.concat(abc); s1 = s1.concat(abc);g)sb1.appe

35、nd(abc); s1 = s1 + s1.concat(abc);34)1. public class lineup public static void main(string args) double d = 12.345; / insert code here 下列哪句代碼放到程序的第4行,可以輸出| 12.345|? ( )a)system.out.printf(|%7d| n, d);b)system.out.printf(|%7f| n, d);c)system.out.printf(|%3.7d| n, d);d)system.out.printf(|%3.7f| n, d);

36、e)system.out.printf(|%7.3d| n, d);f)system.out.printf(|%7.3f| n, d);35)11. public class test public static void main(string args) int x = 5; boolean b1 = true; boolean b2 = false; if (x = 4) & !b2 )system.out.print(1 ); system.out.print(2 ); if (b2 = true) & b1 ) system.out.print(3 ); 程序的輸出結(jié)果是( )a)2

37、b)3c)1 2d)2 3e)1 2 3f)compilation fails.g)an exception is thrown at runtime.36)10. interface foo class alpha implements foo class beta extends alpha class delta extends beta public static void main( string args ) beta x = new beta(); / insert code here 18. 下列哪句代碼放到第16行,可以導(dǎo)致一個(gè)java.lang.classcastexcep

38、tion( )a)alpha a = x;b)foo f = (delta)x;c)foo f = (alpha)x;d)beta b = (beta)(alpha)x;37)22. public void go() string o = ; z: . for(int x = 0; x 3; x+) for(int y = 0; y 2; y+) if(x=1) break; if(x=2 & y=1) break z; o = o + x + y; system.out.println(o); 當(dāng)調(diào)用go方法時(shí),輸出結(jié)果是什么( )a)00b)0001c)000120d)0001202213

39、8)11. static void test() throws runtimeexception try system.out.print(test ); throw new runtimeexception(); catch (exception ex) system.out.print(exception ); public static void main(string args) try test(); catch (runtimeexception ex) system.out.print(runtime ); system.out.print(end ); 程序運(yùn)行結(jié)果是( )a)

40、test endb)compilation fails.c)test runtime endd)test exception ende).a throwable is thrown by main at runtime39)33. try / some code here catch (nullpointerexception e1) system.out.print(a); catch (exception e2) system.out.print(b); finally system.out.print(c); 如果程序的第34行會(huì)拋出一些異常,程序的運(yùn)行結(jié)果是( )a)ab)bc)cd)

41、ace)abc40)31. / some code here try / some code here catch (someexception se) / some code here finally / some code here 哪種情況下37行的代碼會(huì)執(zhí)行,請(qǐng)選擇3個(gè)( )a)the instance gets garbage collected.b)the code on line 33 throws an exception.c)the code on line 35 throws an exception.d)the code on line 31 throws an exce

42、ption.e)the code on line 33 executes successfully.41)10. int x = 0; int y = 10; do y-; +x; while (x 3) system.out.print(pi is bigger than 3. ); else system.out.print(pi is not bigger than 3. ); finally system.out.println(have a nice day.); 程序運(yùn)行結(jié)果是( )a)compilation fails.b)pi is bigger than 3c)an exce

43、ption occurs at runtime.d)pi is bigger than 3. have a nice day.e)pi is not bigger than 3. have a nice day.44)1. public class boxer1 integer i; int x; public boxer1(int y) x = i+y; system.out.println(x); public static void main(string args) new boxer1(new integer(4); 運(yùn)行結(jié)果是( )a)the value 4 is printed

44、at the command line.b)compilation fails because of an error in line 5.c)a nullpointerexception occurs at runtime.d)a numberformatexception occurs at runtime.45)1. public class person private string name; public person(string name) = name; public boolean equals(person p) return .equal

45、s(); 6. 7. 下列哪條語(yǔ)句是正確的( )a)the equals method does not properly override the object.equals method.b)compilation fails because the private attribute cannot be accessed in line 5.c)to work correctly with hash-based data structures, this class must also implement the hashcode method.d)whe

46、n adding person objects to a java.util.set collection, the equals method in line 4 will prevent duplicates.46)1. public class score implements comparable private int wins, losses; public score(int w, int l) wins = w; losses = l; public int getwins() return wins; public int getlosses() return losses; public string tostring() return ; / inse

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論