16、【
单选题
】 请阅读下面程序
import java.io.*;
public class TypeTransition{
public static void main(String args[]){
char a = 'a';
int i = 100;
long y = 456L;
int aa = a + i;
long yy = y-aa;
System.out.print("aa = "+aa);
System.out.print("yy = "+yy);
}
}
程序运行结果是
[2分]
、
aa = 197 yy = 259
、
aa = 177 yy = 259
、
aa = 543 yy = 288\TAB
、
aa = 197 yy = 333\TAB \TAB
答案:
17、【
单选题
】 请阅读下面程序
public class OperatorsAndExpressions {
void residual(){
int i=100,j=30;
float m=563.5f,n=4.0f;
System.out.println(i%j);
System.out.println(m%n);
}
public static void main(String args[]){
OperatorsAndExpressions OperAndExp=new OperatorsAndExpressions();
//取模运算符在整数和浮点数中的应用
OperAndExp.residual();
}
}
程序运行结果是
[2分]
、
10
3.5
、
20
2.5
、
10
4.5
、
20
3.5
答案:
18、【
单选题
】 请阅读下面程序
public class ForLoopStatement {
public static void main(String[] args) {
int i,j;
for(i=1;i<5;i++){ \TAB //i循环
for(j=1;j<=i;j++) \TAB //j循环
System.out.print(i+"×"+j+"="+i*j+" ");
System.out.println();
}
}
}
程序完成后,i循环和j循环执行的次数分别是
[2分]
、
4,10
、
8,9
、
9,8
、
10,10\TAB
答案:
19、【
单选题
】 下列叙述中,错误的是
[2分]
、
Java中,方法的重载是指多个方法可以共享同一个名字
、
Java中,用abstract修饰的类称为抽象类,它不能实例化\TAB
、
Java中,接口是不包含成员变量和方法实现的抽象类
、
Java中,构造方法可以有返回值
答案:
20、【
单选题
】 请阅读下面程序
public class ExampleStringBuffer{
public static void main(String[] args){
StringBuffer sb=new StringBuffer ("test");
System.out.println("buffer ="+sb);
System.out.println("length ="+sb.length());
}
}
程序运行结果中在"length="后输出的值是
[2分]
、
10
、
4
、
20
、
30
答案:
21、【
单选题
】 请阅读下面程序
import java.io.*;
public class ExceptionCatch{
public static void main(String args[]){
try{
FileInputStream fis=new FileInputStream("text");
System.out.println("content of text is:");
}
catch(FileNotFoundException e){
System.out.println(e);
System.out.println("message:"+e.getMessage());
e.printStackTrace(System.out);
}____________________{
System.out.println(e);
}
}
}
为保证程序正确运行,程序中下划线处的语句应是
[2分]
、
catch(FileInputStream fis)
、
e.printStackTrace()\TAB
、
catch(IOException e)
、
System.out.println(e)
答案:
22、【
单选题
】 下列叙述中,错误的是
[2分]
、
所有的字节输入流都从InputStream类继承
、
所有的字节输出流都从OutputStream类继承
、
所有的字符输出流都从OutputStreamWriter类继承
、
所有的字符输入流都从Reader类继承
答案:
23、【
单选题
】 下列叙述中,正确的是
[2分]
、
线程与进程在概念上是不相关的\TAB
、
一个线程可包含多个进程\TAB
、
一个进程可包含多个线程\TAB
、
Java中的线程没有优先级
答案:
24、【
单选题
】 请阅读下面程序
public class ThreadTest{
public static void main(String args[ ]){\TAB
Thread t1 = new Thread( new Hello( ) );
Thread t2 = new Thread( new Hello( ) );\TAB
t1.start( );
t2.start( );
}
}
class Hello implements Runnable{
int i ;
public void run( ){
while( true){
System.out.println("Hello"+i++);
if (i==5) break ;
}
}
}
该程序创建线程使用的方法是
[2分]
、
继承Thread类
、
实现Runnable接口\TAB
、
t1.start()
、
t2.start()
答案:
25、【
单选题
】 Java对I/O访问所提供的同步处理机制是
[2分]
、
字节流
、
过滤流
、
字符流
、
压缩文件流
答案:
26、【
单选题
】 Java对文件类提供了许多操作方法,能获得文件对象父路径名的方法是
[2分]
、
getAbsolutePath()
、
getParentFile()\TAB
、
getAbsoluteFile()
、
getName()
答案:
27、【
单选题
】 下列叙述中,错误的是
[2分]
、
Java中没有检测和避免死锁的专门机制
、
程序中多个线程互相等待对方持有的锁,可能形成死锁
、
为避免死锁,Java程序中可先定义获得锁的顺序,解锁是按加锁的反序释放
、
为避免死锁,Java程序中可先定义获得锁的顺序,解锁是按加锁的正序释放
答案:
28、【
单选题
】 请阅读下面程序
public class ThreadTest {
public static void main(String args[ ]) throws Exception{
int i=0;
Hello t = new Hello( );
__________________;
while( true){
System.out.println("Good Morning"+i++);
if (i == 2 && t.isAlive()){
System.out.println("Main waiting for Hello!");
t.join(); //等待t运行结束
}
if (i==5) break ;}
}
}
class Hello extends Thread{
int i ;
public void run( ){
while( true){
System.out.println("Hello"+i++);
if (i==5) break ;}}}
为使该程序正确执行,下划线处的语句应是
[2分]