JAVA复习资料

合集下载

JAVA复习资料含答案

JAVA复习资料含答案

A、 额外的定义一个实例变量
B、 实现接口中的所有方法
C、 扩展该接口
D、 以上答案都不对
38、利用多态,使用同一个【 D 】可产生不同的操作,这取决于调用方法
的参数类型。
A、方法返回类型 B、 实例变量
C、 局部变量 D、 方法名
39、对静态成员(用 static 修饰的变量或方法)的不正确描述是【 D 】。
D、class
22、下列语句中,对构造方法的描述错误的是【 D 】。
A、构造方法的名称必须和类名相同
B、构造方法没有返回值,返回类型也不能用 void
C、构造方法在一个类中可以多次出现
D、当重写了带参数的构造方法,系统默认的不带参数的构造方法依然存在
23、下面关于 java 中类的说法哪个是不正确的【 C 】。
B、 int x( int a,int b) { return a-b; }
C、 int x( int a,int b ); { return a*b; }
D、 int x(int a,int b) { return 1.2*(a+b); }
19、Java 中所有的类都是通过直接或间接地继承( )类得到的。【 A 】。
45、定义一个包的关键字是【 B 】。
A、import
B、 package C、 interface D、 protected
46、使用 Class 类的【 D 】方法可载入一个数据库驱动
A 、getClass
B、 getName C 、 forClass
D 、 forName
A、类体中只能有变量定义和成员方法的定义,不能有其他语句
B、构造方法是类中的特殊方法
C、类一定要声明为 public 的,才可以执行

Java高级语言程序设计期末复习资料(1)

Java高级语言程序设计期末复习资料(1)

第1章、Java语言简介第2知识点、Java程序的开发过程【单项选择】1 、下列关于classpath环境变量的说法中,哪一个是正确的(难度系数:易)A、classpath配置一次后可永久使用B、没有classpath环境变量就不能运行Java程序C、classpath环境变量可以让虚拟机找到class文件的目录D、查看当前classpath配置的命令是:classpath参考答案:C答案解析:classpath环境变量可以让虚拟机找到class文件目录,没有配置classpath环境变量时,java虚拟机会自动将其设置为“.”。

查看当前classpath的命令是set classpath;【单项选择】2 、在下列说法中,选出最正确的一项是( )。

(难度系数:易)A、Java语言是以类为程序的基本单位的B、Java语言是不区分大小写的C、多行注释语句必须以//开始D、在Java语言中,类的源文件名和该类名可以不相同参考答案:A【单项选择】3 、Java属于以下哪种语言? (难度系数:易)A、机器语言B、汇编语言C、高级语言D、以上都不对参考答案:C答案解析:Java是一门高级编程语言【单项选择】4 、下列选项中不属于Java虚拟机的执行特点的一项是( )。

(难度系数:易)A、异常处理B、多线程C、动态链接D、简单易学参考答案:D【单项选择】5、下列命令中,可以将文档注释提取出来生成帮助文档的是()(难度系数:易)A、javacB、javaC、javadocD、jar参考答案:C答案解析:可以使用javadoc命令将文档注释提取出来生成帮助文档【单项选择】6 、下列关于Java特点的描述中,错误的是?(难度系数:易)A、Java语言不支持指针B、Java具有自动垃圾回收的机制C、Java只能运行在Window和Linux平台D、Java允许多个线程同时执行参考答案:C答案解析:JAVA是一门面向对象的语言,它没有指针的概念,并提供了自动垃圾回收的机制,具有跨平台,多线程等特点。

Java期末复习

Java期末复习

第一章1.面向过程和面向对象程序设计语言的区别2.编译执行和解释执行语言的区别3.java的各个版本,javase javaee javame4.什么是java虚拟机?工作原理是什么?jdk和jre的区别?5.各个命令的含义:javac.exe java.exe Javadoc.exe jar.exe(考试不要求)6.path和classpath的区别(考试不要求)第二章1.标识符的命名规则2.变量使用三部曲:声明,赋值,使用3.如何定义常量?4.基本数据类型(8种),占用的空间大小,给定一个常数,默认的类型,浮点数的两种表示方法5.基本数据类型的转换,向上和向下6.参数可变的方法定义(考试不要求)第三章类和对象(一)类和对象的基本概念*****1.面向对象语言的基本特点2.什么是类和对象,什么是封装性3.java中所有对象都是引用类型。

(内存分析)4.对象的创建和使用(new,.,)5.JVM内存分配,堆、栈、数据、代码(考试不要求)6.java对象生命周期,什么是gc?工作原理?好处?7.构造函数作用,定义要求。

默认构造方法和对类成员的初始化。

构造和初始化顺序(4步)。

8.对象变量的传递,值传递和引用传递9.什么是方法重载?要求是什么?和方法重写有什么区别?10.this引用的作用11.静态数据成员和静态方法成员。

静态成员和普通成员的互相访问(二)包的概念12.什么是包?如何定义包?命名规则是什么?如何使用包?哪些常用包?哪个包不显式导入就可使用?13.使用jar打包(考试不要求)(三)继承的概念*****14.什么是继承?带来的好处是什么?15.如何实现继承?子类成员和父类成员有哪三种关系?新增,重用,重写16.什么是重写?有哪些语法要求?17.super关键字的作用什么?18.子类的构造函数的执行过程。

能否继承父类?如何显式调用父类构造函数?19.类成员的可访问性。

(4个关键字)20.对象转型,向上,向下,instanceof关键字。

JAVA期末复习资料2

JAVA期末复习资料2

Java期末复习题一、判断题1、在Java程序中发生异常时,JVM会找到每个符合条件的catch都执行一次。

( F )2、在Java程序中异常分为运行时异常和非运行时异常,非运行异常必须进行处理( F )3、异常处理的try-catch块后必须有finally块。

( F )4、异常处理器的排列次序影响处理异常的方法。

( T )5、用catch(Exception exception)语句可以捕获所有异常和错误。

( F )6、启动多线程必须调用start()方法, 如果调用run()方法则没有启动新的线程( T )7、run()方法是运行线程的主体,若run方法运行结束,线程就消亡了。

( T )8、线程可以用yield()方法使同优先级的线程运行。

( T )9、一个线程创建并启动后,它将执行自己的run()方法。

( T )10、线程可以用yield()方法使较低优先级的线程运行。

( F )11、每个Java线程的优先级都设置在常数1~12之间,默认的优先级设置为常数6。

(F )12、JFrame,JPanel,JApplet和JButton四种组件都属于容器组件.( F )13、BorderLayout是面板(JPanel)的缺省布局管理器。

( F )14、BorderLayout最多可以使用5个组件。

( T )15、一个面板(JPanel)不能被加入另一个面板(JPanel)中。

( F )16、菜单需要一个JMenuBar对象,以使他们能被添加到JFrame。

( T )17、标签(JLabel)可以在屏幕上显示一个字符或一幅图片。

( T )18、BorderLayout是容器javax.swing.JFrame默认的布局管理器。

(T )19、JTextArea可以用来接收多行文本的输入。

( T )20、在Java坐标系统中,X值从左向右增加。

( T )21、BorderLayout布局管理器把组件排列在北、南、东、西和中间区域。

《Java基础入门》复习资料.doc

《Java基础入门》复习资料.doc
33.System类位于以下哪个包中?
A.java.io B.java.util C.java.awt ng
34.己知类的继承关系如下:
class Employee;
class Manager extends Employee;
class Director extends Employee;
A.tryB.catchC.th rows D.throw
28.关于super关键字以下说法哪些是正确的?(多选)
A.super关键字可以调用父类的构造方法
B.super关键字可以调用父类的普通方法
C.super与this不能同时存在于同一个构造方法中
D.super与this可以同时存在于同一个构造方法中
C.线程进入死亡状态,但是该线程对象仍然是一个Thread对象,在没有被垃圾回收器回收之前仍可以像 引用其它对象一样引用它
D.线程进入死亡状态后,调用它的start。方法仍然可以重新启动
40.对于死锁的描述,下面四种说法正确有哪些?(多选)
A.当两个线程互相等待对方释放同步锁时会发生死锁
BJava虚拟机没有检测和处理死锁的措施
42.线程调用sleep()方法后,该线程将进入以下哪种状态?
A.就绪状态B.运行状态C.阻塞状态D.死亡状态
43.在以下哪种情况下,线程进入就绪状态?
A.线程调用了sleep()方法时B.线程调用了join。方法(终止)
C.线程调用了yield。方法时D.线程调用了notify()方法??
44.下面四个选项中,对线程同步的目的描述正确的有哪些?(多选)
D.编写简单,可以不通过Thread类直接创建线程
39.对于线程的生命周期,下面四种说法正确的有哪些?(多选)

Java语言及面向对象技术复习资料

Java语言及面向对象技术复习资料

Java语言及面向对象技术复习资料一、单项选择题。

1、下列哪个是Java应用程序主类中正确的main方法?()A.public void main(String args[])B.static void main(String args[])C.public static void Main(String args[])D.public static void main(String args[])2、下列哪项是正确的float变量的声明?()A.float foo=-1; B.float foo=1.0;C.float foo=2.02f; D.float foo=0x0123;3、对于int a[]=new int[3];下列哪个叙述是错误的?()A.a.length的值是3。

B.a[1]的值是1。

C.a[0]的值是0。

D.a[a.length-1]的值等于a[2]的值。

4、下列哪个叙述是正确的?()A.5.0/2+10的结果是double型数据。

B.(int)5.8+1.0的结果是int型数据。

C.’苹’+’果’的结果是char型数据。

D.(short)10+’a’的结果是short型数据。

5、对于下列Hello类,哪个叙述是正确的?()A.Hello类有2个构造方法。

B.Hello类的int Hello()方法是错误的方法。

C.Hello类没有构造方法。

D.Hello无法通过编译,因为其中的hello方法的方法头是错误的(没有类型)。

class Hello {Hello (int m) {}int Hello() {Return 20;}hello() {}}6、下列哪个叙述是正确的?()A.成员变量的名字不可以和局部变量的名字相同。

B.方法的参数的名字可以和方法中声明的局部变量的名字相同。

C.成员变量没有默认值。

D.局部变量没有默认值。

7、下列哪个叙述是正确的?()A.子类继承父类的构造方法B.abstract类的子类必须是非abstract类C.子类继承的方法只能操作子类继承和隐藏的成员变量D.子类重写或新增的方法也能直接操作被子类隐藏的成员变量8、下列程序中注释的哪个代码(A,B,C,D)是错误的(无法通过编译)?()class A {static int m;static void f() {m=20; //A}}class B extends A {void f() //B{ m=222; //C}}class E {public static void main(String args[]) {A.f();}}9、将下列哪个代码(A,B,C,D)放入程序中标注的【代码】处将导致编译错误?()A.public float getNum() {return 4.0f;} B.public void getNum() {};C.public void getNum(double d) {}D.public double getNum(float d) {return 4.0d;}class A {public float getNum() {return 3.0f;}}public class B extends A {【代码】}10、下列哪个叙述是正确的?()A. 一个类最多可以实现两个接口B. 如果一个抽象类实现某个接口,那么它必须要重写接口中的全部方法C. 如果一个非抽象类实现某个接口,那么它可以只重写接口中的部分方法D. 允许接口中只有一个抽象方法二、程序填空题。

java复习资料(学生版)

java复习资料(学生版)

1、在Java语言中,所有的数组都有一个length属性,这个属性存储了该数组的(元素个数)。

2、程序中实现多线程的方法有两种:继承( Thread )类和实现( Runnable )接口。

3、下面程序段的执行结果是( 65432 )。

public class l1 {public static void main(String[] args){int a[] = { 2, 3, 4, 5, 6 };for (int i = a.length - 1; i >= 0; i--)System.out .print(a[i] + "");}}4、定义类的构造方法不能有返回值类型,其名称与(类)名相同。

5、取得当前线程的语句是:(Thread.currentThread();)6、构造函数(没有)返回值7、若有类定义:class B extends A{…} ,则类B是类A的(子类)。

8、接口中的成员只有静态常量和(抽象方法)。

9、方法覆盖是指子类重新实现了(父)类中的方法,子类方法的名称、参数列表和(返回值类型)必须与(父)类方法的一致10、在子类中使用关键字( super )做前缀可调用被子类覆盖的父类中的方法。

11、Java语言中, 通常把可能发生异常的代码放到try块中,并用紧跟其后的( catch )块来捕获和处理异常。

12、当线程被创建后,其所处的状态是(新建状态)13、(抽象)方法是一种仅有方法头,没有具体方法体和操作实现的方法,该方法必须在抽象类之中定义。

14、鼠标事件的监听器接口MouseListener能实现的事件包括(单击,按下、释放、移入、移出)。

MouseMotionListener 拖拽移动15、Java语言的类与类之间的是(单)重继承。

16、如果一个类被声明为( final )类型,意味着它在继承关系中必须处于最末端,不能作为父类被继承。

17、在Java中,无需在程序中用import导入的包是(ng.*; )18、使用关键字( final )修饰的方法不允许再以任何形式进行修改,是不能被当前类的子类重新定义的方法。

计算机(专升本)java程序设计复习资料

计算机(专升本)java程序设计复习资料

一卷一、简答题1. 什么是类?什么是对象?2. 方法的重载和覆盖(重写)有什么区别?3. 简述抽象类与接口的异同。

4. 简述JDBC访问数据库的步骤。

二、编程题1. 定义一个类Circle,计算并输出圆(半径=3)的面积2.在D盘创建文件test.txt,文件中的内容为Hello,world!,然后利用输入流输出流把文件拷贝到E盘根目录下。

卷一答案一、简答题 1. 什么是类?什么是对象?类是对某一类事物的描述,是抽象的、概念上的定义;对象是实际存在的该类事物的每个个体,也称实例。

2. 方法的重载和覆盖(重写)有什么区别?方法的重载和重写都是实现多态的方式,区别在于前者实现的是编译时的多态性,而后者实现的是运行时的多态性。

重载发生在一个类中,同名的方法如果有不同的参数列表(参数类型不同、参数个数不同或者二者都不同)则视为重载;重载对返回类型没有特殊的要求。

重写发生在子类与父类之间,重写要求子类被重写方法与父类被重写方法有相同的返回类型,比父类被重写方法更好访问,不能比父类被重写方法声明更多的异常。

3. 抽象类与接口的异同抽象类和接口都不能够实例化,但可以定义抽象类和接口类型的引用。

一个类如果继承了某个抽象类或者实现了某个接口都需要对其中的抽象方法全部进行实现,否则该类仍然需要被声明为抽象类。

接口比抽象类更加抽象,因为抽象类中可以定义构造器,可以有抽象方法和具体方法,而接口中不能定义构造器而且其中的方法全部都是抽象方法。

抽象类中的成员可以是private、默认、protected、public的,而接口中的成员全都是public的。

抽象类中可以定义成员变量,而接口中定义的成员变量实际上都是常量。

有抽象方法的类必须被声明为抽象类,而抽象类未必要有抽象方法。

4. 简述JDBC访问数据库的步骤a) 加载JDBC驱动程序b) 建立数据库连接c) 创建Statement对象d) 执行SQL语句e) 处理返回结果f) 关闭创建的对象二、编程题1. public class Circle {double radius;public Circle(double r){radius=r;}public double area(){return 3.14*r*r;}(8分)public static void main(String[] args) {Circle c=new Circle(3);System.out.println("圆的面积是"+c.area());}}(7分)2.public class FileCopy {public static void main(String[] args) {try {。

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

第一章1.Given the following,1. interface Base {2. boolean m1 ();3. byte m2(short s);4. }Which code fragments willcompile?(Choose all that apply.)A.interface Base2 implements Base { }B.abstract class Class2 extends Base { publicboolean ml() { return true; } }C.abstract class Class2 implements Base { }D.abstract class Class2. implements Base{ public boolean m1() { return (true); } }E.class Class2 implements Base { booleanm1( ) { return false; } byte m2(short s){ return 42; } }2. Which declare a compilable abstract class? (Choose all that apply.)A.public abstract class Canine { public Barkspeak(); }B.public abstract class Canine { public Barkspeak() { } }C.public class Canine { public abstract Barkspeak(); }D.public class Canine abstract{ publicabstract Bark speak(); }3. Which is true? (Choose all that apply. )A."X extends Y" is correct if and only if X isa class and Y is an interface.B."X extends Y" is correct if and only if X isan interface and Y is a class.C."X extends Y" is correct if X and Y areeither both classes or both interfaces.D."X extends Y" is correct for allcombinations of X and Y being classesand/or interfaces.4. Which are valid declarations? (Choose all that apply.)A.int $x;B.int 123;C.int _123;D.int #dim;E.int %percent;F.int *divide;G.intcentral_sales_region_Summer_2005_gross_sales第二章1. Which statement(s) are true? (Choose all that apply.)A.Has-a relationships always rely oninheritance.B.Has-a relationships always rely on instancevariables.C.Has-a relationships always require at leasttwo class types.D.Has-a relationships always rely onpolymorphism.E.Has-a relationships are always tightlycoupled.2.Given:class Clidders {public final void flipper(){ System.out.println("Clidder"); }}public class Clidlets extends Clidders {public void flipper() {System.out.println("Flip a Clidlet");super.flipper();}public static void main(String [] args) {new Clidlets().flipper();}}What is the result?A.Flip a ClidletB.Flip a ClidderC.Flip a ClidderFlip a ClidletD.Flip a ClidletFlip a ClidderE.Compilation fails.3. Given:public abstract interface Frobnicate { public void twiddle(String s) ; }Which is a correct class? (Choose all that apply.)A.public abstract class Frob implementsFrobnicate {public abstract void twiddle(String s){}}B.public abstract class Frob implementsFrobnicate { }C.public class Frob extends Frobnicate {public void twiddle(Integer i) { }}D.public class Frob implements Frobnicate {public void twiddle(Integer i) { }}E.public class Frob implements Frobnicate {public void twiddle(String i) { }public void twiddle(Integer s) { }}4. Given: class Top {public Top(String s) { System.out.print("B"); } }public class Bottom2 extends Top {public Bottom2(String s){ System.out.print("D"); }public static void main(String [] args) {new Bottom2("C");System.out.println(" ");}}What is the result?A.BDB.DBC.BDCD.DBCpilation fails.5. Select the two statements that best indicate a situation with low coupling. (Choose two.)A.The attributes of the class are all private.B.The class refers to a small number of otherobjects.C.The object contains only a small number ofvariables.D.The object is referred to using ananonymous variable, not directly.E.The reference variable is declared for aninterface type, not a class. The interfaceprovides a small number of methods.F.It is unlikely that changes made to oneclass will require any changes in another.6. Given:class Clidder {private final void flipper() { System.out.println ("Clidder"); }}public class Clidlet extends Clidder {public final void flipper(){ System.out.println("Clidlet"); }public static void main(String [] args) {new Clidlet().flipper();}}What is the result?A.ClidletB.ClidderC.ClidderClidletD.ClidletClidderpilation fails.7. Using the fragments below, complete the following code so it compiles. Note, you may not have to fill all of the slots.Code:class AgedP {__________ _________ __________________ _________public AgedP(int x) {_ ________ _ ________ _ _________________ ___________}}public class Kinder extends AgedP {_________ _________ __________________ _________ _________public Kinder(int x) {_________ _________ __________________ ___________() ;}}Fragments: Use the following fragments zero or more times:AgedP super this( ) { }; 8. Given:1. class Plant {2. String getName() { return "plant"; }3. Plant getType() { return this; }4. }5. class Flower extends Plant {6. // insert code here7. }8. class Tulip extends Flower {}Which statement(s), inserted at line 6, will compile? (Choose all that apply.)A.Flower getType() { return this; }B.String getType() { return "this"; }C.Plant getType() { return this; }D.Tulip getType() { return new Tulip() ;}9. Given:1. class Zing {2. protected Hmpf h;3. }4. class Woop extends Zing { }5. class Hmpf { }Which is true? (Choose all that apply.)A.Woop is-a Hmpf and has-a zing.B.zing is-a Woop and has-a Hmpf.C.Hmpf has-a Woop and Woop is-a Zing.D.Woop has-a Hmpf and Woop is-a zing.E.Zing has-a Hmpf and Zing is-a Woop.10. Given:1. class Programmer {2. Programmer debug() { return this; }3. }4. class SCJP extends Programmer {5. // insert code here6. }Which, inserted at line 5, will compile? (Choose all that apply.)A.Programmer debug() { return this; }B.SCJP debug() { return this; }C.Object debug() { return this; }D.int debug() { return 1; }E.int debug(int x) { return 1; }F.Object debug (int x) { return this; }第四章1. Given:class Hexy {public static void main(String[] args) {Integer i = 42;String s =(i<40)?"life":(i>50)?"universe":"everything";System.out.println(s);}}What is the result?A.nullB.lifeC.universeD.everythingpilation fails.F.An exception is thrown at runtime.2. Given:1. class Example {2. public static void main(String[] args) {3. Short s = 15;4. Boolean b;5. // insert code here6. }7. }Which, inserted independently at line 5, will compile? (Choose all that apply.)A. b = (Number instanceof s);B. b = (s instanceof Short);C. b = s.instanceof(Short);D. b = (s instanceof Number);E. b = s.instanceof(Object);F. b = (s instanceof String);3. Given:1. class Comp2 {2. public static void main(String[] args) {3. float f1 = 2.3f;4. float[][] f2 = {{42.Of}, {l.7f, 2.3f}, {2.6f, 2.7f}};5. float[] f3 = {2.7f};6. Long x = 42L;7. // insert code here8. System.out.println("true");9. }10. }And the following five code fragments:F1. if (f1 == f2)F2.if (f1 == f2[2][1])F3. if (x == f2[0][0])F4. if (f1 == f2 [1,1] )F5. if (f3 == f2 [2] )What is true?A.One of them will compile, only one will betrue.B.Two of them will compile, only one willbe true.C.Two of them will compile, two will betrue.D.Three of them will compile, only one willbe true.E.Three of them will compile, exactly twowill be true.F.Three of them will compile, exactly threewill be true.4. Given:class Fork {public static void main(String[] args) {if(args.length == 1 | args[1] .equals("test")) {System.out.println ("test case");} else {System.out.println("production " +args[0]) ;}}}And the command-line invocation:java Fork live2What is the result?A.test caseB.productionC.test case live2pilation fails.E.An exception is thrown at runtime.5. Given:class Foozit {public static void main(String[] args) {Integer x = 0;Integer y = 0;for(Short z = 0; z < 5; z++)if((++x > 2) || (++y > 2))X++ ;System.out.println (x + " " + y);}}What is the result?A. 5 1B. 5 2C. 5 3D.8 1E.8 2F.8 3G.10 2H.10 3第六章4. Given:Class TKO {public static void main(String[] args) {String s = "-";Integer x = 343;long L343 = 343L;if(x.equals(L343)) s += ".e1 ";if(x.equals(343)) s += ".e2 ";Short s1 = (short)((new Short((short)343)) / (new Short((short)49)));if (s1 == 7) s += "=s ";if(sl < new Integer(7+1)) s += "fly ";System.out.println(s);}}Which of the following will be included in the output String s? (Choose all that apply.)A..e1B..e2C.=sD.flyE.None of the above.pilation fails.G.An exception is thrown at runtime.5. Given:1. import java.text.*;2. class DateOne {3. public static void main(String[] args) {4. Date d = new Date(1123631685981L);5. DateFormat df = new DateFormat();6. System.out.println(df.format(d));7. }8. }And given that 1123631685981L is the number of milliseconds between Jan. 1, 1970, and sometime on Aug. 9, 2005, what is the result? (Note: the time of day in option A may vary.)A.8/9/05 5:54 PMB.1123631685981L,C.An exception is thrown at runtime.pilation fails due to a single error inthe code.pilation fails due to multiple errors inthe code.6. Given:import java.io.*;class Keyboard { }public class Computer implements Serializable {private Keyboard k = new Keyboard(); public static void main(String[] args)Computer c = new Computer();c.storeIt(c) ;}void storeIt(Computer c) {try {ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream("myFile"));os.writeObject(c);os.close() ;System.out.println("done");} catch (Exception x){System.out.println("exc"); } }}}What is the result? (Choose all that apply.)A.excB.donepilation fails.D.Exactly one object is serialized.E.Exactly two objects are serialized.7. Using the fewest fragments possible (and filling the fewest slots possible), complete the code below so that the class builds a directory named "dir3" and creates a file named "file3" inside "dir3". Note you can use each fragment either zero or one times.Code:import java.io.________________class Maker {public static void main(String [] args) {___________ _________________________________ _________________________________ _________________________________ _________________________________ _________________________________ _________________________________ ______________________}}Fragments:File; FileDescriptor; FileWriter; Directory;try { .createNewDir(); File dirFile{ } (Exception x) ("dir3");filefile .createNewFile(); = new File = new Filedir (dir, "file3"); (dir,file); .createFile() ;} catch ("dir3", "file3"); .mkdir(); File file第七章1. Given:import java.util.*;class Test {public static void main(String[] args) {// insert code herex.add("one");x.add("two");x. add ("TWO");System.out.printIn(x.poll());}}Which, inserted at // insert code here, will compile? (Choose all that apply.)A.List<String> x = newLinkedList<String>();B.TreeSet<String> x = newTreeSet<String>();C.HashSet<String> x = newHashSet<String>();D.Queue<String> x = newPriorityQueue<String>();E.ArrayList<String> x = newArrayList<String>();F.LinkedList<String> x = newLinkedList<String>();2. Given:public static void main(String[] args) {// INSERT DECLARATION HEREfor (int i = 0; i <= 10; i++) {List<Integer> row = newArrayList<Integer>();for (int j = 0; j <= 10; j++)row.add(i * j);table.add(row);}for (List<Integer> row : table)System.out.println(row);}Which statements could be inserted at // INSERT DECLARATION HERE to allow this code to compile and run? (Choose all that apply.)A.List<List<Integer>> table = newList<List<Integer>>();B.List<List<Integer>> table = newArrayList<List<Integer>>();C.List<List<Integer>> table = newArrayList<ArrayList<Integer>>();D.List<List, Integer> table = new List<List,Integer>();E.List<List, Integer> table = newArrayList<List, Integer>();F.List<List, Integer> table = newArrayList<ArrayList, Integer>();G.None of the above.3. Which statements are true about comparing two instances of the same class, given that the equals() and hashCode() methods have been properly overridden? (Choose all that apply.)A.If the equals() method returns true, thehashCode() comparison == might returnfalse.B.If the equals() method returns false, thehashCode() comparison == might returntrue.C.If the hashCode() comparison == returnstrue, the equals() method must return true.D.If the hashCode() comparison == returnstrue, the equals() method might return true.E.If the hashCode() comparison ! = returnstrue, the equals() method might return true.15. Given:12. TreeSet map = new TreeSet();13. map.add("one");14. map.add("two");15. map.add("three");16. map.add("four"};17. map.add("one");18. Iterator it = map.iterator();19. while (it.hasNext() ) {20. System.out.print( it.next() + " " );21. }What is the result?pilation fails.B.one two three fourC.four three two oneD.four one three twoE.one two three four oneF.one four three two oneG.An exception is thrown at runtime.H.The print order is not guaranteed.16. Given a method declared as:public static <E extends Number> List<? super E> process(List<E> nums)A programmer wants to use this method like this: // INSERT DECLARATIONS HEREoutput = process(input);Which pairs of declarations could be placed at // INSERT DECLARATIONS HERE to allow the code to compile? (Choose all that apply.)A.ArrayList<Integer> input = null;ArrayList<Integer> output = null;B.ArrayList<Integer> input = null;List<Integer> output = null;C.ArrayList<Integer> input = null;List<Number> output = null;D.List<Number> input = null;ArrayList<Integer> output = null;E.List<Number> input = null;List<Number> output = null;F.List<Integer> input = null;List<Integer> output = null;G.None of the above.第九章1. Given:public class Messager implements Runnable { public static void main(String[] args) {new Thread(newMessager("Wallace")).start() ;new Thread(newMessager("Gromit")).start();}private String name;public Messager(String name) { = name; }public void run() {message(1);message(2);}private synchronized void message(int n) {System.out.print(name + "-" + n + " ");} }Which of the following is a possible result? (Choose all that apply.)A.Wallace-1 Wallace-2 Gromit-1B.Wallace-1 Gromit-2 Wallace-2 Gromit-1C.Wallace-1 Gromit-1 Gromit-2 Wallace-2D.Gromit-1 Gromit-2E.Gromit-2 Wallace-1 Gromit-1 Wallace-2F.The code does not compile.G.An error occurs at run time.2. Given:public class Letters extends Thread {private String name;public Letters(String name) { = name;}public void write () {System.out.print(name);System.out.print(name);}public static void main(String[] args) {new Letters("X").start();new Letters("Y").start();}}We want to guarantee that the output can be either XXYY or YYXX, but never XYXY or any other combination. Which of the following method definitions could be added to the Letters class to make this guarantee? (Choose all that apply.)A.public void run() { write(); }B.public synchronized void run() { write(); }C.public static synchronized void run(){ write(); }D.public void run() { synchronized(this){ write(); } }E.public void run(){ synchronized(Letters.class) { write(); } }F.public void run () { synchronized(System.out) { write (); } }G.public void run(){ synchronized(System.out.class){ write(); } }3. The following block of code creates a Thread using a Runnable target:Runnable target = new MyRunnable();Thread myThread = new Thread(target);Which of the following classes can be used to create the target, so that the preceding code compiles correctly?A.public class MyRunnable extendsRunnable{public void run(){}}B.public class MyRunnable extendsObject{public void run(){}}C.public class MyRunnable implementsRunnable{public void run(){}}D.public class MyRunnable implementsRunnable{void run(){}}E.public class MyRunnable implementsRunnable{public void start(){}}4. Given:2. class MyThread extends Thread {3. public static void main(String [] args) {4. MyThread t = new MyThread();5. t.start() ;6. System.out.print("one. ");7. t.start();8. System.out.print("two. ");9. }10. public void run() {11. System.out.print("Thread "};12. }13. }What is the result of this code?pilation fails.B.An exception occurs at runtime.C.Thread one. Thread two.D.The output cannot be determined.5. Given:3. class MyThread extends Thread {4. public static void main(String [] args) {5. MyThread t = new MyThread () ;6. Thread x = new Thread(t);7. x.start();8. }9. public void run() {10. for(int i=0;i<3;++i) {11. System.out.print(i + "..");12. }13. }14. }What is the result of this code?pilation fails.B.1‥2‥3‥C.0‥1‥2‥3‥D.0‥1‥2‥E.An exception occurs at runtime.。

相关文档
最新文档