下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、面试测试题 2(一)、选择题(4 'X 10):( 1 ) Which of the following range of short is correct? CA. -27 27-1 B. 0 216-1 C. -215 215-1 D. -231 231-1( 2 ) Which declarations of identifiers are legal? ABEA. $persons B. TwoUsers C. *point D. this E. _endline( 3 ) Given the following code: C1 : public void modify()
2、2:int i, j, k;3:i = 100;4:while ( i > 0 ) 5:j = i * 2;6: System.out.println (" The value of j is " + j );7:k = k + 1;8:i-;9: 10: Which line might cause an error during compilation? CA. line 4 B. line 6 C. line 7 D. line 8( 4) Which of the following answer is correct to express the value
3、 8 in octal number? AA. 010 B. 0x10 C. 08 D. 0x8( 5 ) Which are not Java keywords?ABA. TRUE B. sizeof C. const D. super E. void( 6 ) Given the following code:1 : class Person 2: public void printValue(int i, int j) /. 3:public void printValue(int i)/. 4: 5: public class Teacher extends Person 6: pub
4、lic void printValue() /. 7: public void printValue(int i) /.8: public static void main(String args)9: Person t = new Teacher();10: t.printValue(10);11: 12: Which method will the statement on line 10 call? DA. on line 2 B. on line 3 C. on line 6 D. on line 7( 7 ) Given the following code:public void
5、test() try oneMethod();System.out.println("condition 1"); catch (ArrayIndexOutOfBoundsException e) System.out.println("condition 2"); catch(Exception e) System.out.println("condition 3"); finally System.out.println("finally");Which will display if oneMethod ru
6、n normally?ADA. condition 1B. condition 2C. condition 3D. finally(8) Given the following code:public class Test void printValue(int m) do System.out.println("The value is"+m); while( -m > 10 );public static void main(String arg) int i=10;Test t= new Test(); t.printValue(i);Which will be
7、 output? CA. The value is 8B. The value is 9C. The value is 10D. The value is 11(9) Given the following code: public class Personstatic int arr = new int10; public static void main(String a) System.out.println(arr1;) Which statement is correct?CA. When compilation some error will occur.B. It is corr
8、ect when compilation but will cause error when running.C. The output is zero.D. The output is null.(10) Given the following code: String s = "hello"String t = "hello" char c = 'h','e','l','l','o' ;Which return true? ADA. s.equals(t);B. t.eq
9、uals(c);C. s=t;D. t.equals(new String("hello");E. t=c.1、C2、A、B、E3、C4、A5、A、B6、D7、A、D8、C9、C10、A、D(二八填空题(4 'X 5):(1)、 String str = new String ( “ Practical ”) ;str +=“ Java ” ;共产生几个对象:5。(2)、递归函数sum(int a,int n)的返回值是数组 a的前n个元素之和int sum(int a,int n) if (n>0) return _a0+sum(a+1,n-1);else
10、_return 0;( 3)、 short s1 = 1; s1 = s1 + 1 和 short s1 = 1; s1 += 1; 那个可以编译通过,为什么第二个 第一个 丢失精度 (4)、设 int x=1,y=2,z=3, 则表达式 y+=z-/+x 的值是 _3 。( 5)、 import java.util.*;class Int private int i;public Int(int ii) i = ii; public void increment() i+; public String toString() return Integer.toString(i);public
11、class test public static void main(String args) ArrayList v = new ArrayList();for(int i = 0; i < 10; i+ )v.add(new Int(i);System.out.println("v: " + v);ArrayList v2 = (ArrayList)v.clone();for(Iterator e = v2.iterator();e.hasNext(); )(Int)e.next().increment();System.out.println("v:
12、" + v);上面这段代码输出什么 v: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9_v: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 。1、5 个2、an-1+sum(a,n-1) 或 a0+sum(a+1,n-1)return 03、第二个(第一个丢失精度)4、35、v: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9v: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10(1)、(15')请编写程序打印下列图案:(2)、 (25' )Java 异常处理机制测试继承 Exception 类编写一个自定义异常类 MyE
13、xception, 在自定义异常类中加入一个方法 getMyMessage(),此方法无参数,返回值为一个字符串,字符串内容为你的自定义异常信息:"你的姓名:"+ Exception的getMessage()方法的返回值.格式如:(姓名 :*Exception* )。编写一个类 ExceptionMaker, 在里面定义一个方法 throwException(), 在这个方法中制造一种异 常情况,抛出一个JDK自带的异常,捕捉这个异常 拼在catch处理语句中抛出你的自定义异常MyException,抛出的自定义异常要求保留原异常的信息(getMessage()的返回值);
14、再编写一个类MyExceptio nTestCase,测试你编写的前面两个类,调用第二个类中的抛出你自定义异常的方法 throwException(), 捕捉你的自定义异常 ,并输出你自定义的异常信息 .答案(三)编程题1、public class Test01 public static void main(String args) int i, j, t, c;j = 1;t = 9;c = 5;while(c > 0)for(i = 0; i <= j; i+)System.out.print(" ");j+;for(i = 0; i < t; i+
15、)2、/*System.out.print("*");t -= 2;System.out.println();c-;* 自定义的异常类*/class MyException extends Exception private String str;/* 抛出异常*return 抛出异常串*/public String getMyMessage() return str;/* 构造自定义异常*param 发生的异常*/public MyException(Exception e) Exception excep = new Exception(e); str = "zhanggenbo" + excep.getMessage();/*自定义的异常类*/ class ExceptionMaker /* 扑获异常 */public void throwException() throws ArithmeticException, MyException try int i = 3 / 0; catch (ArithmeticException e) System.out.println(e.getMessage(); throw new MyExcepti
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026天津港保税区临港社区卫生服务中心派遣制人员招聘5人笔试参考题库及答案解析
- 2026重庆医科大学附属第三医院招聘岗位18人考试备考试题及答案解析
- 2026广西崇左天等县供销社招聘企业管理人员3人考试参考试题及答案解析
- 2025年县乡教师选调考试《教育学》真题及答案详解【网校专用】
- 2026年西安建筑科技大学图书馆招聘(3人)笔试参考题库及答案解析
- 2025年注册消防工程师之《消防安全技术实务》考前冲刺模拟题库有完整答案详解
- 现代出版社招聘图书编辑2名、音乐营销编辑1名笔试备考试题及答案解析
- 2026海南海口美兰国际机场有限责任公司招聘笔试备考题库及答案解析
- 2026北京朝阳区亚运村社区卫生服务中心招聘2人考试备考试题及答案解析
- 2026云南省投资控股集团有限公司集中招聘考试备考题库及答案解析
- 新课标语文整本书阅读教学课件:童年(六下)
- 【RCEP背景下中国对日本农产品出口贸易SWOT及发展对策10000字(论文)】
- CJ/T 124-2016 给水用钢骨架聚乙烯塑料复合管件
- 电影赏析绿皮书课件(内容详细)
- 横山县众源煤矿矿山地质环境保护与土地复垦方案
- 打造宜居城市创造舒适宜居的居住环境
- 信阳职业技术学院单招《职业技能测试》参考试题库(含答案)
- 全麻术后舌后坠护理
- 跨期入账整改报告
- 适老化工程改造合同范本
- 离婚协议书电子版下载
评论
0/150
提交评论