Java Test Two

 

《Java测试题2》
一、 选择
1.欲构造ArrayList类的一个实例,此类继承了List接口,下列哪个方法是正确的 ? B
A ArrayList myList=new Object();
B List myList=new ArrayList();
C ArrayList myList=new List();
D List myList=new List();
2.paint()方法使用哪种类型的参数? A
A Graphics
B Graphics2D
C String
D Color
3.指出正确的表达式 C
A byte=128;
B Boolean=null;
C long l=0xfffL;
D double=0.9239d;
4.指出下列程序运行的结果 B
public class Example{
  String str=new String("good");
  char[]ch={'a','b','c'};
  public static void main(String args[]){
    Example ex=new Example();
    ex.change(ex.str,ex.ch);
    System.out.print(ex.str+" and ");
    Sytem.out.print(ex.ch);
  }
  public void change(String str,char ch[]){
    str="test ok";
    ch[0]='g';
  }
}
A good and abc
B good and gbc
C test ok and abc
D test ok and gbc
5.运行下列程序, 会产生什么结果 A
public class X extends Thread implements Runable{
 public void run(){
  System.out.println("this is run()");
 }
 public static void main(String args[])
 {
  Thread t=new Thread(new X());
  t.start();
 }
}
A 第一行会产生编译错误
B 第六行会产生编译错误
C 第六行会产生运行错误
D 程序会运行和启动
6.要从文件" file.dat"文件中读出第10个字节到变量C中,下列哪个方法适合? 
A FileInputStream in=new FileInputStream("file.dat"); in.skip(9); int c=in.read();
B FileInputStream in=new FileInputStream("file.dat"); in.skip(10); int c=in.read();
C FileInputStream in=new FileInputStream("file.dat"); int c=in.read();
D RandomAccessFile in=new RandomAccessFile("file.dat"); in.skip(9); int c=in.readByte();
7.容器被重新设置大小后,哪种布局管理器的容器中的组件大小不随容器大小的变化而改变? B
A CardLayoutB FlowLayout
C BorderLayout
D GridLayout
8.给出下面代码: C
public class Person{
  static int arr[] = new int[10];

  public static void main(String a[])
  {
   System.out.println(arr[1]);
  }
}
那个语句是正确的?
A 编译时将产生错误;
B 编译时正确,运行时将产生错误;
C 输出零;
D 输出空。
9.哪个关键字可以对对象加互斥锁? B
A transient
B synchronized
C serialize
D static
10.下列哪些语句关于内存回收的说明是正确的? B
A 程序员必须创建一个线程来释放内存;
B 内存回收程序负责释放无用内存
C 内存回收程序允许程序员直接释放内存
D 内存回收程序可以在指定的时间释放内存对象
11.下列代码哪几行会出错: c
1) public void modify() {
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) }
A line 4
B line 6
C line 7
D line 8
二、多项选择
1.执行下列代码后,哪个结论是正确的 String[] s=new String[10]; BD
A s[10] 为 "";
B s[9] 为 null;
C s[0] 为 未定义
D s.length 为10
2.下面的表达式哪个是正确的?AE
A String s="你好";int i=3; s+=i;
B String s="你好";int i=3; if(i==s){ s+=i};
C String s="你好";int i=3; s=i+s;
D String s="你好";int i=3; s=i+;
E. String s=null; int i=(s!=null)&&(s.length>0)?s.length():0;
3.选出合理的标识符AC
A _sys1_lll
B 2mail
C $change
D class
4.哪个布局管理器使用的是组件的最佳尺寸( preferred size) AE
A FlowLayout
B BorderLayout
C GridLayout
D CardLayout
E.GridBagLayout
5.下列哪个方法可用于创建一个可运行的类?AE
A public class X implements Runable{ public void run(){ ......} }
B public class X implements Thread{ public void run(){ ......} }
C public class X implements Thread{ public int run(){ ......} }
D public class X implements Runable{ protected void run(){ ......} }
E.public class X implements Thread{ public void run(){ ......} }
6.下面哪个方法可以在任何时候被任何线程调用?DEF
A notify()
B wait()
C notifyAll()
D sleep()
E.yield()
F.synchronized(this)
7.构造BufferedInputStream的合适参数是哪个? AC
A BufferedInputStream
B BufferedOutputStream
C FileInputStream
D FileOuterStream
E. File
8.下列说法正确的是 BC
A java.lang.Clonable是类
B java.lang.Runnable是接口
C Double对象在java.lang包中
D Double a=1.0是正确的java语句
9.指出正确的表达式AB

B Double a=new Double(1.0);
C byte a = 340;
D Byte a = 120;
10.定义一个类名为"MyClass.java"的类,并且该类可被一个工程中的所有类访问,那么该类的正确声明应为:CD
A double a=1.0;
A private class MyClass extends Object
B class MyClass extends Object
C public class MyClass
D public class MyClass extends Object
11.指出下列哪个方法与方法public void add(int a){}为合理的重载方法。 CD


A public int add(int a)
B public void add(long a)
C public void add(int a,int b)
D public void add(float a)
12.如果下列的方法能够正常运行,在控制台上将显示什么? ACD

public void example(){
  try{
    unsafe();
    System.out.println("Test1");
    }
    catch(SafeException e)
    {System.out.println("Test 2");}
  finally{System.out.println("Test 3");}
  System.out.println("Test 4");
}
A Test 1
B Test 2
C Test 3
D Test 4
13.下列哪些情况可以终止当前线程的运行? ABD
A 抛出一个例外时。
B 当该线程调用sleep()方法时。
C 当创建一个新线程时。
D 当一个优先级高的线程进入就绪状态时。
三、 填空题
1.执行下列代码后的结果是什么? int x,a=2,b=3,c=4; x=++a+b+++c++;
2. 包包含了Collection的接口和类的API
.main方法的声明格式包括
4.下列程序中构造了一个SET并且调用其方法add(),输出结果是
public class A{
public int hashCode(){return 1;}
public Boolean equals(Object b){return true}
public static void main(String args[]){ Set set=new HashSet();
set.add(new A());
set.add(new A());
set.add(new A());
System.out.println(set.size());
}
}
5.下列程序的运行结果是
class A{
class Dog{
  private String name;
  private int age;
  public int step;
  Dog(String s,int a){
   name=s;
   age=a;
   step=0;
   }
  public void run(Dog fast){
  fast.step++;
  }
}

  public static void main (String args[]){
  A a=new A();
  Dog d=a.new Dog("Tom",3);
  d.step=25;
  d.run(d);
  System.out.println(d.step);
  }
}

答案::填空第1题
x=10,a=3,b=4,c=5
填空第2题
java.util
填空第3题
(public )(static )(void)(main)(String args[])
填空第4题
1
填空第5题
26  

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值