JAVA基础面试题1.doc

上传人:仙人指路1688 文档编号:2386804 上传时间:2023-02-17 格式:DOC 页数:13 大小:54KB
返回 下载 相关 举报
JAVA基础面试题1.doc_第1页
第1页 / 共13页
JAVA基础面试题1.doc_第2页
第2页 / 共13页
JAVA基础面试题1.doc_第3页
第3页 / 共13页
JAVA基础面试题1.doc_第4页
第4页 / 共13页
JAVA基础面试题1.doc_第5页
第5页 / 共13页
点击查看更多>>
资源描述

《JAVA基础面试题1.doc》由会员分享,可在线阅读,更多相关《JAVA基础面试题1.doc(13页珍藏版)》请在三一办公上搜索。

1、JAVA语言基础笔试题-1Question 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(String args) 7. (TestA)new TestB().start(); / TestA x=new TestB(); x.start();8. 9

2、. What is the result?A. TestAB. TestBC. Compilation fails.D. An exception is thrown at runtime.答案:B考点:继承环境下,父类引用变量指向子类的问题。说明:继承环境下,父类引用变量指向子类对象时调用的方法应从子类先找,如果子类没有找到再从父类中查找。Question 2Given:1. interface TestA String toString(); 2. public class Test 3. public static void main(String args) 4. System.out

3、.println(new TestA() 5. public String toString() return “test”; 6. );7. 8. What is the result?A. testB. nullC. An exception is thrown at runtime.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.答案

4、:A考点:接口的考察。说明:本体在输出语句中直接创建TestA的对象,并在语句中完成并且调用toString()方法。Question 3Given:11. public abstract class Shape 12. int x;13. 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

5、class.Which is correct?A. Shape s = new Shape();s.setAnchor(10,10);s.draw();B. Circle c = new 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.dr

6、aw();答案:B考点:考察子类继承和抽象类的问题。说明:在继承和抽象类中,子类对象不能调用父类的方法,当父类引用变量指向之类对行时,指代的是父类的部分,不能调用子类的方法。抽象类中未完成的放法不能被调用,只有完成了方法才能被调用。Question 4Given:10. abstract public class Employee 11. protected abstract double getSalesAmount();12. public double getCommision() 13. return getSalesAmount() * 0.15;14. 15. 16. class

7、Sales extends Employee 17. / insert method here18. Which two methods, inserted independently at line 17, correctlycomplete 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.

8、protected double getSalesAmount() return 1230.45; 答案:AB考点:抽象类被继承时,方法的可见度问题。说明:当抽象类被继承时,子类必须重写父类的抽象方法,且子类的方法可见度必须比父类的可见度更广。Question 5Given:10. interface Data public void load(); 11. abstract class Info public abstract void load(); Which class correctly uses the Data interface and Info class?A. public

9、 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 something */ public void Info.load() /*do something

10、*/ 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 something */ public void Info.load() /*do something*/ F. public class Employee extends

11、Info implements Datapublic void Data.load() /*do something*/ public void Info.load() /*do something*/ 答案:A考点:抽象类和接口在继承和继承接口中的问题。说明:子类可以同时继承抽象类和接口类,子类的必须必须重写抽象类和接口的方法。如果抽象类和接口有相同的未完成的方法名,这子类中只要写一个就可以。Question 6Given:11. public abstract class Shape 12. private int x;13. private int y;14. public abstra

12、ct 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. public class Circle implements Shape private int radius;B. public abstract class Circle extends Shape private int radius;C. public class Circl

13、e extends Shape private int radius;public void draw();D. public abstract class Circle implements Shape private int radius;public 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;p

14、ublic void draw() / code here */ 答案:E考点:继承环境下,抽象类的抽象放法被继承时的问题.说明:抽象类被继承时应使用extends,且抽象类中的抽象方法应给在子类中完成。Question 7Which two classes correctly implement both the java.lang.Runnableand the java.lang.Clonable interfaces? (Choose two.)A. public class Sessionimplements Runnable, Clonable public void run();

15、public Object clone();B. public class Sessionextends Runnable, Clonable public void run() / do something */ public Object clone() / make a copy */ C. public class Sessionimplements Runnable, Clonable public void run() / do something */ public Object clone() /* make a copy */ D. public abstract class

16、 Sessionimplements Runnable, Clonable public void run() / do something */ public Object clone() /*make a copy */ E. public class Sessionimplements Runnable, implements Clonable public void run() / do something */ public Object clone() / make a copy */ 答案:CE考点:考察接口被子类继承的规则。说明:接口被继承时应在类后面写上被继承的接口,且要完成

17、接口中所有未完成的方法。Question 8Click 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 void go() System.out.println(”go in Sente.”

18、); 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 Gobango in Sentego in SenteB. go in Sentego in Sentego in GobanC. go in Sentego in Goba

19、ngo in GobanD. go in Gobango in Gobango in SenteE. Compilation fails because of an error in line 17.答案:C考点:考察接口被实现和的问题。说明:本题考察接口被实现时应重写接口中的方法,当一个子类同时继承和实现接口时,在两父类中都有的方法,在子类中只需继承非接口父类的方法或重写父类的方法。Question 9Given:11. public static void parse(String str) 12. try 13. float f= Float.parseFloat(str);14. ca

20、tch (NumberFormatException nfe) 15. f= 0;16. finally 17. System.out.println(f);18. 19. 20. public static void main(String args) 21. parse(“invalid”);22. What is the result?A. 0.0B. Compilation fails.C. A ParseException is thrown by the parse method at runtime.D. A NumberFormatException is thrown by

21、the parse method atruntime.答案:B考点:考察异常和变量定义问题。说明:本题通过异常来考察变量定义的使用块,在try块中定义的f不能在catch块中不能再使用f,否则将导致编译错误。Question 10Click 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

22、output from line 5 of the Test class?A. 5B. 10C. 12D. 17E. 24答案:C考点:考察形参与实参的用法。说明:本题method()方法被调用且把5赋值给形参后,在方法中只改变形参的值,不管形参如何改变,都不影响实参的值。Question 11Given:55. int x= 1, 2,3,4, 5; / new int1,2,3,4,556. int y =x;57. System.out.println(y2);Which is true?A. Line 57 will print the value 2.B. Line 57 will

23、print the value 3.C. Compilation will fail because of an error in line 55.D. Compilation will fail because of an error in line 56.答案:B考点:考察数组的用法。说明:本题数组x把值赋给数组y,再通过数组下标来找数值。Question 12Given:35. String #name = “Jane Doe”;36. int $age=24;37. Double _height = 123.5;38. double temp = 37.5;Which two are

24、true? (Choose 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考点:标示符的用法。说明:标识符由大小写字母,下划线,数字,$符号组成,开头可以是大小写字母,下划线,和$符号。Question13Which two code fragments correctly create and initialize a static arrayof int elements? (Choose tw

25、o.)A. static final int a = 100,200 ;B. static final int a;static a=new int2; a0=100; a1=200; C. static final int a = new int2 100,200 ;D. static final int a;static void init() a = new int3; a0=100; a1=200; 答案:AC考点:考察数组的定义。说明:一个数组可以直接初始化,系统会制动帮你创建,也可以创建后在初始化。Question 14Given:11. public static void ma

26、in(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 3B. Compilation fails because of an error in line 12.C. Compilation fails because of an error in line 13.D. Compilation fails because of an err

27、or in line 14.E. A ClassCastException is thrown at runtime.答案:A考点:考察数组的用法。说明:本题创建一个数组赋给它的引用变量为obj,在通过obj把数组的地址赋给array。Question 15Given:10. class Foo 11. static void alpha() /* more code here */ 12. void beta() /* more code here */ 13. Which two are true? (Choose two.)A. Foo.beta() is a valid invocat

28、ion 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 method beta().答案:Question 16A programmer needs to create a logging method that can accept anarbitrary number of arguments. For example, it may be called

29、 in theseways:logIt(”log message 1 “);logIt(”log message2”,”log message3”);logIt(”log message4”, “log message5”, “log message6“);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(Str

30、ing msg1, String msg2, String msg3)Question 17A programmer is designing a class to encapsulate the informationabout an inventory item. A JavaBeans component is needed todo this. The Inventoryltem class has private instance variables to storethe item information:.10. private int itemId;11. private St

31、ring name;12. private String description;Which method signature follows the JavaBeans naming standards formodifying 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 18Click the Exhibit button

32、.1. public class A 2.3. private int counter = 0;4.5. public 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

33、. Compilation of class 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 19A JavaBeans component has the following field:11. private boolean enab

34、led;Which two pairs of method declarations follow the JavaBeans standardfor 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 enabled)public boo

35、lean isEnabled()D. public boolean setEnabled( boolean enabled)public boolean getEnabled()Question 2041. 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 extends Two 17. / insert method here18. Which two methods,

36、 inserted individually, correctly complete the Threeclass? (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() return this; Question 21Given:10. class One 11. void foo() 12. 13. class Two extends One

37、 14. /insert method here15. Which three methods, inserted individually at line 14, will correctlycomplete class Two? (Choose three.)A. int foo() /* more code here */ B. void foo() /* more code here */ C. public void foo() /* more code here */ D. private void foo() /* more code here */ E. protected v

38、oid foo() /* more code here */ Question 22Click the Exhibit button.1. public interface A 2. public void doSomething(String thing);3. 1. public class AImpl implements A 2. public void doSomething(String msg) 3. 1. public class B 2. public A doit() 3. / more code here4. 5.6. public String execute() 7.

39、 / more code here8. 9. 1. public class C extends B 2. public AImpl doit() 3. / more code here4. 5.6. public Object execute() 7. / more code here8. 9. Which statement is true about the classes and interfaces in theexhibit?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.

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 建筑/施工/环境 > 项目建议


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号