java试题库程序分析题

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

1、 试题序号:502 2、 题型:程序分析题 3、 难度级别:3 4、 知识点:成员变量的初始化(4-3) 5、 分值:6
6、 所需时间:5 7、 试题关键字: 8、 试题内容: 请写出下面程序的执行结果。 class Measurement { boolean t=true; char c; byte b; short s; int i; long l; float f; double d; void print() { System.out.println( "Data type Initial value\n" + "boolean " + t + "\n" + "char [" + c + "] "+ (int)c +"\n"+ "byte " + b + "\n" + "short " + s + "\n" + "int " + i + "\n" + "long " + l + "\n" + "float " + f + "\n" + "double " + d); } } public class InitialValues { public static void main(String[] args) { Measurement d = new Measurement(); d.print(); /* In this case you could also say: new Measurement().print(); */ } } ///:~ 9、 答案内容: Data type Initial value Boolean true char [ ] 0 byte 0 short 0 int 0 long 0 float 0.0
9、 答案内容: javac A.java (1) java C (2) B's fun1 is calling (3) A's fun2 is calling (4) 10、 评分细则:1,2 每行答对得 1 分,3,4 之间顺序正确两分,内容正确各得 1 分。
1、 试题序号:507 2、 题型:程序分析题 3、 难度级别:4 4、 知识点:访问控制修饰符(5-2) 5、 分值:6 6、 所需时间:5 7、 试题关键字: 8、 试题内容: 请在下表中填入合适的符号(其中”√”表示可以访问,”×”表示不能访问) 修饰符 同一个类 同一个包 不同包,子类 public 无 protected private 9、 答案内容: 修饰符 public 无 protected private 10、 同一个类 √ √ √ √ 同一个包 √ √ √ √ 不同包,子类 √
1、 试题序号:505 2、 题型:程序分析题 3、 难度级别:5 4、 知识点:类和对象初始化的顺序(5-4) 5、 分值:6 6、 所需时间:10
7、 试题关键字: 8、 试题内容: 试分析下面这个程序执行的顺序,将给出注释的六行代码的执行先后次序写出来。 class Insect { int i = 9; int j; Insect() { prt("i = " + i + ", j = " + j); j = 39; } static int x1 = prt("static Insect.x1 initialized"); static int prt(String s) { System.out.println(s); return 47; } }
1、 试题序号:501 2、 题型:程序分析题 3、 难度级别:2 4、 知识点:继承(5-4) 5、 分值:6 6、 所需时间:5 7、 试题关键字:extends 8、 试题内容: 下面程序的输出结果是:_________ class Art { Art() { System.out.println("Art constructor"); } } class Drawing extends Art { Drawing() { super(); System.out.println("Drawing constructor"); } } public class Cartoon extends Drawing { Cartoon() { super(); System.out.println("Cartoon constructor"); } public static void main(String[] args) { Cartoon x = new Cartoon(); } } 9、 答案内容: Art constructor Drawing constructor Cartoon constructor 10、 评分细则:顺序完全正确得满分 6 分,其中任意两个顺序错误扣 3 分,全部顺序错 误不得分
10、
double 0.0 评分细则:答案整体框架 1 分,value 错一个扣 0.5 分
1、 试题序号:503 2、 题型:程序分析题 3、 难度级别:3 4、 知识点:继承(5-4) 5、 分值:6 6、 所需时间:5 7、 试题关键字: 8、 试题内容: 试写出下面程序的执行结果. package test; public class FatherClass { public FatherClass() { System.out.println(“FatherClass Create”); } } 子类: package test; import test.FatherClass; public class ChildClass extends FatherClass { public ChildClass() { System.out.println(“ChildClass Create”); } public static void main(String[] args) { FatherClass fc = new FatherClass(); ChildClass cc = new ChildClass(); } } 9、 答案内容: FatherClass Create FatherClass Create ChildClass Create 评分细则:缺少中间那个 FatherClass Create 扣 3 分,顺序错误扣 2 分。
所有类
所有类 √
评分细则:打错一个地方扣 0.5 分
1、 试题序号:508 2、 题型:程序分析题 3、 难度级别:3 4、 知识点:构造函数的重载(5-3) 5、 分值:6 6、 所需时间:5 7、 试题关键字: 8、 试题内容:
写出下面程序的输出结果 class C0 { public C0(int x) { System.out.println("C0"+x); } C0() {System.out.println("C0");} } class C1 extends C0{ public C1(int x) { System.out.println("C1"+x); } public static void main (String args[]) { new C1(1); } } 9、 答案内容: c0 c11 10、 评分细则:答案顺序占 2 分,其中每个答案书写是否正确占 2 分
// 1
//2
public class Beetle extends Insect { int k = prt("Beetle.k initialized"); //3 Beetle() { //4 prt("k = " + k); prt("j = " + j); } static int x2 = prt("static Beetle.x2 initialized"); //5 static int prt(String s) { System.out.println(s); return 63; } public static void main(String[] args) { prt("Beetle constructor"); //6 Beetle b = new Beetle(); } } ///:~ 9、 答案内容:256134 10、 评分细则:看具体回答与答案的顺序的区别扣分。
class c { static int x = 20; int y = 30; static int plus() { return x+y; } public static void main(String [] args ) { int result = plus(); System.out.println(“result = “ + result); 9、 答案内容: 1)int[3]={2,4,8}; 因为数组在声明的时候不能指定大小,所以改成 int[] a={2,4,8}; 2)int y=30 因为后面的 plus()方法是静态的,其中有对 y 的调用,所以 y 必须是静态的 所以这里改为 static int y=30; 10、 评分细则:每个程序说明错在什么地方得 1 分,说明如何修改得 2 分。
10、
Байду номын сангаас
1、 试题序号:504 2、 题型:程序分析题 3、 难度级别:4 4、 知识点:异常捕获语句(12-2) 5、 分值:6 6、 所需时间:8 7、 试题关键字: 8、 试题内容: 试写出下面这个程序的执行结果. class ExceptionTest { static String a[] = {"123", "abc", null}; public static void main (String args[]) { for (int i = 0; i < 3; i++) { try { int x = Integer.parseInt(a[i]); System.out.println( "Result: " + x); } catch(NullPointerException e) { System.out.println("error null:");} catch (NumberFormatException e) {System.out.println("error:abc" );} finally{System.out.println ("In "+ i +"th loop\n"); } //end for } } 9、 答案内容: Result: 123 In 0th loop error:abc In 1th loop error abc:In 2th loop 10、 评分细则:每个小项 1 分, }
1、 试题序号:506 2、 题型:程序分析题 3、 难度级别:4
4、 知识点:继承(5-4) 5、 分值:6 6、 所需时间:8 7、 试题关键字: 8、 试题内容: 下面这个程序命名为 A.java,在答案纸上面写出编译以及执行它的命令行,并写出执行后 的结果。 class A { void fun1() { System.out.println("A's fun1 is calling"); } void fun2() { System.out.println("A's fun2 is calling"); } } class B extends A { void fun1() { System.out.println("B's fun1 is calling"); } void fun3() { System.out.println("B's fun3 is calling"); } } class C { public static void main(String[] args) { B b = new B(); call (b); } static void call(A a) { a.fun1(); a.fun2(); } }
1、 试题序号:509 2、 题型:程序分析题 3、 难度级别:3 4、 知识点:数组(6-1) ,static 修饰的静态数据成员(4-3) 5、 分值:6 6、 所需时间:10 7、 试题关键字: 8、 试题内容: 下面两个程序是否有错?如果有错试标出错误位置并指出是何种错误。 程序 1 class ArraySum { int a[3] = { 2, 4, 8}; int sum () { int s=0; for (int i = 0; i < 3; i ++) s = s+ a[i]; return s; } } 程序 2.
相关文档
最新文档