JAVA基础面试题1_第1页
JAVA基础面试题1_第2页
JAVA基础面试题1_第3页
JAVA基础面试题1_第4页
JAVA基础面试题1_第5页
已阅读5页,还剩8页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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 str

31、ing 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 enabl

34、ed;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 bool

35、ean 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, 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. pu

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论