JAVA基礎(chǔ)面試題1

上傳人:仙*** 文檔編號:28991762 上傳時間:2021-09-23 格式:DOC 頁數(shù):13 大?。?6KB
收藏 版權(quán)申訴 舉報 下載
JAVA基礎(chǔ)面試題1_第1頁
第1頁 / 共13頁
JAVA基礎(chǔ)面試題1_第2頁
第2頁 / 共13頁
JAVA基礎(chǔ)面試題1_第3頁
第3頁 / 共13頁

下載文檔到電腦,查找使用更方便

15 積分

下載資源

還剩頁未讀,繼續(xù)閱讀

資源描述:

《JAVA基礎(chǔ)面試題1》由會員分享,可在線閱讀,更多相關(guān)《JAVA基礎(chǔ)面試題1(13頁珍藏版)》請在裝配圖網(wǎng)上搜索。

1、JAVA語言基礎(chǔ)筆試題-1 Question 1 (43) Given: 1. class TestA { 2. public void start() { System.out.println(”TestA”); } 3. } 4. public class TestB extends TestA { 5. public void start() { System.out.println(”TestB”); } 6. public static void main

2、(String[] args) { 7. ((TestA)new TestB()).start(); // TestA x=new TestB(); x.start(); 8. } 9. } What is the result? A. TestA B. TestB C. Compilation fails. D. An exception is thrown at runtime. 答案:B 考點(diǎn):繼承環(huán)境下,父類引用變量指向子類的問題。 說明:繼承環(huán)境下,父類引用變量指向子類對象時調(diào)用的方法應(yīng)從子類先找,如果子類沒有找到再從父類中查找。 Question 2

3、 Given: 1. interface TestA { String toString(); } 2. public class Test { 3. public static void main(String[] args) { 4. System.out.println(new TestA() { 5. public String toString() { return “test”; } 6. }); 7. } 8. } What is the result? A. test B. null C. An exception is thrown at runtim

4、e. D. Compilation fails because of an error in line 1. E. Compilation fails because of an error in line 4. F. Compilation fails because of an error in line 5. 答案:A 考點(diǎn):接口的考察。 說明:本體在輸出語句中直接創(chuàng)建TestA的對象,并在語句中完成并且調(diào)用toString()方法。 Question 3 Given: 11. public abstract class Shape { 12. int x; 1

5、3. int y; 14. public abstract void draw(); 15. public void setAnchor(int x, int y) { 16. this.x = x; 17. this.y = y; 18. } 19. } and a class Circle that extends and fully implements the Shape class. Which is correct? A. Shape s = new Shape(); s.setAnchor(10,10); s.draw(); B. Circle c = n

6、ew Shape(); c.setAnchor(10,10); c.draw(); C. Shape s = new Circle(); s.setAnchor(10,10); s.draw(); D. Shape s = new Circle(); s->setAnchor(10,10); s->draw(); E. Circle c = new Circle(); c.Shape.setAnchor(10,10); c.Shape.draw(); 答案:B 考點(diǎn):考察子類繼承和抽象類的問題。 說明:在繼承和抽象類中,子類對象不能調(diào)用父類的方法,當(dāng)父類引用變量指向

7、之類對行時,指代的是父類的部分,不能調(diào)用子類的方法。抽象類中未完成的放法不能被調(diào)用,只有完成了方法才能被調(diào)用。 Question 4 Given: 10. abstract public class Employee { 11. protected abstract double getSalesAmount(); 12. public double getCommision() { 13. return getSalesAmount() * 0.15; 14. } 15. } 16. class Sales extends Employee { 17. // inse

8、rt method here 18. } Which two methods, inserted independently at line 17, correctly complete the Sales class? (Choose two.) A. double getSalesAmount() { return 1230.45; } B. public double getSalesAmount() { return 1230.45; } C. private double getSalesAmount() { return 1230.45; } D. protected

9、 double getSalesAmount() { return 1230.45; } 答案:AB 考點(diǎn):抽象類被繼承時,方法的可見度問題。 說明:當(dāng)抽象類被繼承時,子類必須重寫父類的抽象方法,且子類的方法可見度必須比父類的可見度更廣。 Question 5 Given: 10. interface Data { public void load(); } 11. abstract class Info { public abstract void load(); } Which class correctly uses the Data interface and In

10、fo class? A. public class Employee extends Info implements Data { public void load() { /*do something*/ } } B. public class Employee implements Info extends Data { public void load() { /*do something*/ } } C. public class Employee extends Info implements Data { public void load() { /*do some

11、thing */ } public void Info.load() { /*do something*/ } } D. public class Employee implements Info extends Data { public void Data.load() { /*d something */ } public void load() { /*do something */ } } E. public class Employee implements Info extends Data { public void load() { /*do somethin

12、g */ } public void Info.load(){ /*do something*/ } } F. public class Employee extends Info implements Data{ public void Data.load() { /*do something*/ } public void Info.load() { /*do something*/ } } 答案:A 考點(diǎn):抽象類和接口在繼承和繼承接口中的問題。 說明:子類可以同時繼承抽象類和接口類,子類的必須必須重寫抽象類和接口的方法。如果抽象類和接口有相同的未完成的方法名,這子類中只

13、要寫一個就可以。 Question 6 Given: 11. public abstract class Shape { 12. private int x; 13. private int y; 14. public abstract void draw(); 15. public void setAnchor(int x, int y) { 16. this.x = x; 17. this.y = y; 18. } 19. } Which two classes use the Shape class correctly? (Choose two.) A. p

14、ublic class Circle implements Shape { private int radius; } B. public abstract class Circle extends Shape { private int radius; } C. public class Circle extends Shape { private int radius; public void draw(); } D. public abstract class Circle implements Shape { private int radius; public

15、 void draw(); } E. public class Circle extends Shape { private int radius; public void draw() {/* code here */} } F. public abstract class Circle implements Shape { private int radius; public void draw() { / code here */ } } 答案:E 考點(diǎn):繼承環(huán)境下,抽象類的抽象放法被繼承時的問題. 說明:抽象類被繼承時應(yīng)使用extends,且抽象類中的抽象方法應(yīng)

16、給在子類中完成。 Question 7 Which two classes correctly implement both the java.lang.Runnable and the java.lang.Clonable interfaces? (Choose two.) A. public class Session implements Runnable, Clonable { public void run(); public Object clone(); } B. public class Session extends Runnable, Clon

17、able { public void run() { / do something */ } public Object clone() { / make a copy */ } } C. public class Session implements Runnable, Clonable { public void run() { / do something */ } public Object clone() { /* make a copy */ } } D. public abstract class Session implements Runnable, Cl

18、onable { public void run() { / do something */ } public Object clone() { /*make a copy */ } } E. public class Session implements Runnable, implements Clonable { public void run() { / do something */ } public Object clone() { / make a copy */ } } 答案:CE 考點(diǎn):考察接口被子類繼承的規(guī)則。 說明:接口被繼承時應(yīng)在類后面寫上被繼承的

19、接口,且要完成接口中所有未完成的方法。 Question 8 Click the Exhibit button. 1. public class GoTest { 2. public static void main(String[] args) { 3. Sente a = new Sente(); a.go(); 4. Goban b = new Goban(); b.go(); 5. Stone c = new Stone(); c.go(); 6. } 7. } 8. 9. class Sente implements Go { 10. public vo

20、id go() { System.out.println(”go in Sente.”); } 11. } 12. 13. class Goban extends Sente { 14. public void go() { System.out.println(”go in Goban”); } 15. } 16. 17. class Stone extends Goban implements Go { } 18. 19. interface Go { public void go(); } What is the result? A. go in Goban go

21、 in Sente go in Sente B. go in Sente go in Sente go in Goban C. go in Sente go in Goban go in Goban D. go in Goban go in Goban go in Sente E. Compilation fails because of an error in line 17. 答案:C 考點(diǎn):考察接口被實現(xiàn)和的問題。 說明:本題考察接口被實現(xiàn)時應(yīng)重寫接口中的方法,當(dāng)一個子類同時繼承和實現(xiàn)接口時,在兩父類中都有的方法,在子類中只需繼承非接口父類的方法或重寫父類的方

22、法。 Question 9 Given: 11. public static void parse(String str) { 12. try { 13. float f= Float.parseFloat(str); 14. } catch (NumberFormatException nfe) { 15. f= 0; 16. } finally { 17. System.out.println(f); 18. } 19. } 20. public static void main(String[] args) { 21. parse(“invalid”);

23、 22. } What is the result? A. 0.0 B. Compilation fails. C. A ParseException is thrown by the parse method at runtime. D. A NumberFormatException is thrown by the parse method at runtime. 答案:B 考點(diǎn):考察異常和變量定義問題。 說明:本題通過異常來考察變量定義的使用塊,在try塊中定義的f不能在catch塊中不能再使用f,否則將導(dǎo)致編譯錯誤。 Question 10 Click

24、 the Exhibit button. 1. public class Test { 2. int x= 12; 3. public void method(int x) { 4. x+=x; 5. System.out.println(x); 6. } 7. } Given: 34. Test t = new Test(); 35. t.method(5); What is the output from line 5 of the Test class? A. 5 B. 10 C. 12 D. 17 E. 24 答案:C 考點(diǎn):考察形參與實參的用法。

25、 說明:本題method()方法被調(diào)用且把5賦值給形參后,在方法中只改變形參的值,不管形參如何改變,都不影響實參的值。 Question 11 Given: 55. int[] x= {1, 2,3,4, 5}; // new int[]{1,2,3,4,5} 56. int y[] =x; 57. System.out.println(y[2]); Which is true? A. Line 57 will print the value 2. B. Line 57 will print the value 3. C. Compilation will fail be

26、cause of an error in line 55. D. Compilation will fail because of an error in line 56. 答案:B 考點(diǎn):考察數(shù)組的用法。 說明:本題數(shù)組x把值賦給數(shù)組y,再通過數(shù)組下標(biāo)來找數(shù)值。 Question 12 Given: 35. String #name = “Jane Doe”; 36. int $age=24; 37. Double _height = 123.5; 38. double ~temp = 37.5; Which two are true? (Ch

27、oose two.) A. Line 35 will not compile. B. Line 36 will not compile. C. Line 37 will not compile. D. Line 38 will not compile. 答案:BC 考點(diǎn):標(biāo)示符的用法。 說明:標(biāo)識符由大小寫字母,下劃線,數(shù)字,$符號組成,開頭可以是大小寫字母,下劃線,和$符號。 Question13 Which two code fragments correctly create and initialize a static array of int element

28、s? (Choose two.) A. static final int[] a = { 100,200 }; B. static final int[] a; static { a=new int[2]; a[0]=100; a[1]=200; } C. static final int[] a = new int[2] { 100,200 }; D. static final int[] a; static void init() { a = new int[3]; a[0]=100; a[1]=200; } 答案:AC 考點(diǎn):考察數(shù)組的定義。 說明:一個數(shù)組可以直接初始

29、化,系統(tǒng)會制動幫你創(chuàng)建,也可以創(chuàng)建后在初始化。 Question 14 Given: 11. public static void main(String[] args) { 12. Object obj =new int[] { 1,2,3 }; 13. int[] someArray = (int[])obj; 14. for (int i: someArray) System.out.print(i +“ “) 15. } ‘What is the result? A. 1 2 3 B. Compilation fails because of an err

30、or in line 12. C. Compilation fails because of an error in line 13. D. Compilation fails because of an error in line 14. E. A ClassCastException is thrown at runtime. 答案:A 考點(diǎn):考察數(shù)組的用法。 說明:本題創(chuàng)建一個數(shù)組賦給它的引用變量為obj,在通過obj把數(shù)組的地址賦給array。 Question 15 Given: 10. class Foo { 11. static void alpha(

31、) { /* more code here */ } 12. void beta() { /* more code here */ } 13. } Which two are true? (Choose two.) A. Foo.beta() is a valid invocation of beta(). B. Foo.alpha() is a valid invocation of alpha(). C. Method beta() can directly call method alpha(). D. Method alpha() can directly call me

32、thod beta(). 答案: Question 16 A programmer needs to create a logging method that can accept an arbitrary number of arguments. For example, it may be called in these ways: logIt(”log message 1 “); logIt(”log message2”,”log message3”); logIt(”log message4”, “l(fā)og message5”, “l(fā)og message6“);

33、 Which declaration satisfies this requirement? A. public void logIt(String * msgs) B. public void logIt(String [] msgs) C. public void logIt(String... msgs) D. public void logIt(String msg1, String msg2, String msg3) Question 17 A programmer is designing a class to encapsulate the inf

34、ormation about an inventory item. A JavaBeans component is needed to do this. The Inventoryltem class has private instance variables to store the item information: 10. private int itemId; 11. private String name; 12. private String description; Which method signature follows the JavaBeans nam

35、ing standards for modifying the itemld instance variable? A. itemID(int itemId) B. update(int itemId) C. setItemId(int itemId) D. mutateItemId(int itemId) E. updateItemID(int itemId) Question 18 Click the Exhibit button. 1. public class A { 2. 3. private int counter = 0; 4. 5. p

36、ublic static int getInstanceCount() { 6. return counter; 7. } 8. 9. public A() { 10. counter++; 11. } 12. 13. } Given this code from Class B: 25. A a1 =new A(); 26. A a2 =new A(); 27. A a3 =new A(); 28. System.out.printIn(A.getInstanceCount() ); What is the result? A. Compilation of c

37、lass A fails. B. Line 28 prints the value 3 to System.out. C. Line 28 prints the value 1 to System.out. D. A runtime error occurs when line 25 executes. E. Compilation fails because of an error on line 28. Question 19 A JavaBeans component has the following field: 11. private boolean ena

38、bled; Which two pairs of method declarations follow the JavaBeans standard for accessing this field? (Choose two.) A. public void setEnabled( boolean enabled) public boolean getEnabled() B. public void setEnabled( boolean enabled) public void isEnabled() C. public void setEnabled( boolean e

39、nabled) public boolean isEnabled() D. public boolean setEnabled( boolean enabled) public boolean getEnabled() Question 20 41. Given: 10. class One { 11. public One foo() { return this; } 12. } 13. class Two extends One { 14. public One foo() { return this; } 15. } 16. class Three e

40、xtends Two { 17. // insert method here 18. } Which two methods, inserted individually, correctly complete the Three class? (Choose two.) A. public void foo() { } B. public int foo() { return 3; } C. public Two foo() { return this; } D. public One foo() { return this; } E. public Object foo(

41、) { return this; } Question 21 Given: 10. class One { 11. void foo() {} 12. } 13. class Two extends One { 14. //insert method here 15. } Which three methods, inserted individually at line 14, will correctly complete class Two? (Choose three.) A. int foo() { /* more code here */ } B.

42、void foo() { /* more code here */ } C. public void foo() { /* more code here */ } D. private void foo() { /* more code here */ } E. protected void foo() { /* more code here */ } Question 22 Click the Exhibit button. 1. public interface A { 2. public void doSomething(String thing); 3

43、. } 1. public class AImpl implements A { 2. public void doSomething(String msg) { } 3. } 1. public class B { 2. public A doit() { 3. // more code here 4. } 5. 6. public String execute() { 7. // more code here 8. } 9. } 1. public class C extends B { 2. public AImpl doit() { 3. // more

44、code here 4. } 5. 6. public Object execute() { 7. // more code here 8. } 9. } Which statement is true about the classes and interfaces in the exhibit? A. Compilation will succeed for all classes and interfaces. B. Compilation of class C will fail because of an error in line 2. C. Compilation of class C will fail because of an error in line 6. D. Compilation of class AImpl will fail because of an error in line 2.

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

相關(guān)資源

更多
正為您匹配相似的精品文檔

相關(guān)搜索

關(guān)于我們 - 網(wǎng)站聲明 - 網(wǎng)站地圖 - 資源地圖 - 友情鏈接 - 網(wǎng)站客服 - 聯(lián)系我們

copyright@ 2023-2025  zhuangpeitu.com 裝配圖網(wǎng)版權(quán)所有   聯(lián)系電話:18123376007

備案號:ICP2024067431-1 川公網(wǎng)安備51140202000466號


本站為文檔C2C交易模式,即用戶上傳的文檔直接被用戶下載,本站只是中間服務(wù)平臺,本站所有文檔下載所得的收益歸上傳人(含作者)所有。裝配圖網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對上載內(nèi)容本身不做任何修改或編輯。若文檔所含內(nèi)容侵犯了您的版權(quán)或隱私,請立即通知裝配圖網(wǎng),我們立即給予刪除!