java期中(讲完第9章之..

上传人:第*** 文档编号:32804256 上传时间:2018-02-12 格式:DOC 页数:14 大小:93KB
返回 下载 相关 举报
java期中(讲完第9章之.._第1页
第1页 / 共14页
java期中(讲完第9章之.._第2页
第2页 / 共14页
java期中(讲完第9章之.._第3页
第3页 / 共14页
java期中(讲完第9章之.._第4页
第4页 / 共14页
java期中(讲完第9章之.._第5页
第5页 / 共14页
点击查看更多>>
资源描述

《java期中(讲完第9章之..》由会员分享,可在线阅读,更多相关《java期中(讲完第9章之..(14页珍藏版)》请在金锄头文库上搜索。

1、备注:本文档凡注明 “X”标记的都是上次习题课未讲解的,但可以在此讲解。 其他的已经在前面的习题课中讲过。 习题 001、选择填空(可多选)(1)-(E) 代码如下:public class WhileExm public static void main (String args) int x= 1, y = 6; while (y-) x-; system.out.printIn(“x=” + x “y =” + y); 结果是什么? A. The output is x = 6 y = 0 B. The output is x = 7 y = 0 C. The output is x =

2、 6 y = -1 D. The output is x = 7 y = -1 E. 编译失败(2)-(ACD)下面关于变量及其范围的陈述哪些是对的?A. 实例变量是类的成员变量。B. 实例变量用关键字 static 声明。C. 在方法中定义的局部变量在该方法被执行时创建D. 局部变量在使用前必须被初始化。(3)- (AC) X哪些声明阻止了方法的 overriding? A. final void methoda() B. static void methoda() C. static final void methoda() D. final abstract void methoda()

3、 (4)- (A) X哪个语句创建了一个数组实例? A. int ia = new int 15; B. float fa = new float 20; C. char ca = “Some String”; D. int ia = 4, 5, 6 1, 2, 3; 答案 D 的格式错误: 应该为 int ia = 4, 5, 6, 1, 2, 3;(5)-(BC)哪些代码行不会产生编译错误? A. int i=0; if (i) System.out.println(“Hi”); B. boolean b=true; boolean b2=true; if(b=b2) System.out

4、.println(“So true”); C. int i=1; int j=2;if(i=1| j=2) System.out.println(“OK”); D. int i=1; int j=2; if (i=1 &| j=2) System.out.println(“OK”); (6)-(DE) X哪些语句可以合法的插入标明*的位置? class Person private int a;public int change(int m) return m; public class Teacher extends Person public int b;public static voi

5、d main(String arg)Person p = new Person();Teacher t = new Teacher();int i;*A. i = m;B. i = b;C. i = p.a; D. i = p.change(30);E. i = t.b. (7) (源码在 workspace 中工程文件夹名字是 testchapter07) X阅读下列程序,并给出下列程序运行的输出结果:class Person public int a=1;public int change(int m) return m; public class Teacher extends Pers

6、on public int a=2;public static void main(String arg)Person p = new Person();Teacher t = new Teacher();p=t;System.out.println(p.a= +p.a);System.out.println(t.a= +t.a);(答案: p.a= 1t.a= 2)(解释: 在 java 中, 除了非静态方法有动态绑定之外, 实例变量和静态方法都不存在动态绑定的问题, 也就是说, 实例变量和静态方法是在编译时确定其执行内容的, 运行时不再改变 )(8)-(B)编译 Java 源程序文件产生的

7、字节码文件的扩展名为A java B class C html D exe(9)-(BC)下面哪些不是 java 的简单数据类型? A. shortB. BooleanC. DoubleD. float (10)-(BD) 有关构造方法,下列叙述正确的是? A. 默认的构造方法初始化方法变量。B. 默认的构造方法初始化了在类中声明的实例变量。C. 假如一个类缺少没有参数的构造方法,但是有其它的构造方法,则编译器生成一个缺省的构造方法。D. 编译器只有当一个类没有其它的构造方法时才生成缺省的构造方法。 (11 )what is the result when you compile and ru

8、n the following code? (D)(p96)Class ExamplePublic static void main(String args) If(new Boolean(“true”)=new Boolean(“true”) System.out.println(“True”);else System.out.println(“False”);Select all right answers: A. Compilation error;B. No compilation error, but runtime exception;C: Prints “True”;D: Pri

9、nts “False”.考察两个对象的比较:两个属于包装类的对象的比较,就是两个对象的比较(12)-(C) X以下能正确定义数组并正确赋初值的语句是( )A. int n=5, ann; B. int b=2,3;C. int c=1,2,3,4,5; D. int d=1,2,3,4; 习题 00: 在空白处填上合适的语句,使程序能正确运行.(System.out.println(obj.getX();) public class ClassName private int x;Classname() X=1; int getX() return x; public class Testpu

10、blic static void main(String args) ClassName obj=new ClassName(); /生成一个对象_ /在此空白处填上输出 x 的语句 习题 01: 分析下面的类的输出: Xpublic class TStatictester public int x=1;public static int y=2;public static void main(String args) TStatictester t1=new TStatictester();TStatictester t2=new TStatictester();t1.x +=1;t1.y

11、+=1;t2.x +=2;t2.y +=2;System.out.println(T1: x=+t1.x+, y=+t1.y);System.out.println(T2: x=+t2.x+, y=+t2.y);习题 02:请指出下面程序有何错误: Xpublic class pet public String name;public int age;public void readinput ()System.out.println(please enter the name .);name=SavitchIn.readLine();System.out.println(please ent

12、er the age.);age=SavitchIn.readLineInt();public void update(String name ,int age )name=name+ty;age=age+7;public static void main (String args)pet a=new pet();a.readinput();a.update(name,age); 习题 03:请指出下面程序的运行结果(因有一定篇幅,不易在黑板讲解,留做自学) Xpublic class Flower int petalCount = 0;String s = new String(null);

13、Flower(int petals) petalCount = petals;System.out.println(Constructor w/ int arg only, petalCount= + petalCount); Flower(String ss) System.out.println(Constructor w/ String arg only, s=+ ss);s = ss; Flower(String s, int petals) this(petals);/ ! this(s); / Cant call two!this.s = s; / Another use of t

14、hisSystem.out.println(String Flower() this(hi, 47);System.out.println(default constructor (no args);void print() / ! this(11); / Not inside non-constructor!System.out.println(petalCount = + petalCount + s =+ s);public static void main(String args) Flower x = new Flower();x.print();习题 04:分析下列程序的执行结果: Xabstract class AbstractItabstract float getfloat();public class AbstractTest extends AbstractIt private float f1=1.0f;private float getFloat() return f1; 。 。

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 建筑/环境 > 工程造价

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号