JAVA双语教学考试试B卷及答案.docx

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

注意事项:
请将各题答案按编号顺序填写到答题卷上,答在试卷上无效。

一、单选题(本题共40小题,每小题1分,共40分〉
1. What is the return-type of the methods that implement the MouseListener interface?
A. boolean
B. Boolean
C. void
D. Point 2. Select valid identifier of Java:
A. %passwd
B. 3d_game
C. Scharge
D. this
3・ Which declares an abstract method in an abstract Java class? I
A. public abstract method();
B. public abstract void method();
C. public void abstract Method(};
D. public abstract void method() {}
4・ Which statement about listener is true?
A ・ Most component unallow multiple listeners to be added ・
B. If multiple listener be add to a single component, the event only affected one listener.
C. Component don't allow multiple listeners to be add ・
D ・ The listener mechanism allows you to call an addXxxxListener method as many times as is needed, specifying as many different listeners as your design require ・
Which method you define as the starting point of new thread in a class from which new the thread can be excution? A. public void start() B ・ public void run()
C. public void int()
D. public static void main(String argsf]) 6. Which statement is correctly declare a variable a which is suitable for refering to an array of 50 string empty object?
A. String [] a
B. String a
C. char a[][]
D. String a[50]
7. Which cannot be added to a Container?
8. Which is the main() methocPs return of a application?
0|P
A. a Menu
B. a Component
C. a Container
D. an Applet
A. String
B. byte
C. char
D. void
Which is corrected argument of main() method of application?
A. String args B・ String ar[]
C. Char args[][]
D. StringBuffer arg fl Float s=new Float(0.9F);
Float t=new Float(0.9F);
Double u=new Double(0.9);
Which expression s result is true?
A. s==t
B. s.equals(t)
C. s==u
D. t.equals(u)
11. Which are not Java keyword?
A. It must be anonymous
B. It can not implement an interface
C. It is only accessible in the enclosing class
D ・ It can access any final variables in any enclosing scope ・
17. What is written to the standard output given the following statement: System.out.println(4|7);
Select the right answer: A.4
B.5
C.6
D.7
18. A class design requires that a particular member variable must be accessible for direct access by any subclasses of
this class ・ but otherwise not by classes which are not members of the same package ・ What should be done to achieve this?
A ・ The variable should be marked public
B ・ The variable should be marked private C. The variable should be marked protected
D. The variable should have no special access modifier 19. main 方法是Java
Application 稈•序执行的入口点,关于main 方法的方法头以下哪项是合法的
()?
A) public static void main ()
B) public static void main ( String argsf]) C) public static int main (String [] arg ) D) public void main (String arg[]) 20.
卜•面哪种注释方法能够支持javadoc 命令:
A) /**...**/ B) /*...*/
C) //
D) /**...*/
21. Java Application 源程序的主类是指包含有()方法的类。

A) main 方法
B) toString 方法
A. goto
B. null
C. FALSE 12・ Run a corrected class: java -cs AClass a b c <enter>
Which statement is true? A. args[0]=''・cs''; B. args[l J =,,
a b c"; C. args[O[=''java'';
13. Short answer:
The decimal value of i is 12, the octal i value is: A. 14 B. 014
C. 0x14 14. Short answer:
The decimal value of i is 7, the hexadecimal i value is: A.7 B. 07 C. 0x7 15. Which is the range of char?
A. -27-27-l
B.0-216-l
C. 0-216
16. Which statement is true about an inner class?
D. const
D. args[0y;
D. 012
D. x07 D.0~28
C ) init 方法
D ) actionPerfromed 方法
22. Java 的字符类型釆用的是Unicode 编码方案,每个Unicode 码占用()个比特位。

A ) 8 B ) 16 C ) 32 D ) 64
23. 设a = 8,则表达式a»>2的值是()。

A ) 1 B ) 2 C ) 3 D ) 4
24. 若需要定义一个类域或类方法,应使用哪种修饰符?() A ) static B ) package C ) private D ) public
25. 若在某一个类定义中定义有如下的方法:abstract void performDial ();该方法属于( )。

A )本地方法
B )最终方法
C )解态方法
D )抽象方法
26. 下列关于静态初始化块的叙述中,哪一个是正确的?( )
A ) 静态初始化块是在构造函数之前加上static 修饰符。

B ) 静态初始化块是对类自身进行初始化。

C ) 静态初始化块在同一个类屮只能有一个。

D ) 静态初始化块是在其所属的类加载内存时由系统自动调用执行。

27. 不使用static 修饰符限定的方法称为对象(或实例)方法,下列哪一个说法是正确的?( )
A ) 实例方法可以直接调用父类的实例方法。

B ) 实例方法可以直接调用父类的类方法。

C ) 实例方法可以直接调用其他类的实例方法。

D ) 实例方法可以直接调用本类的类方法。

问:类Person 和类Student 的关系是()。

A )包含关系
B )继承关系
29. 在Java 中,一个类可同时定义许多同名的方法,这些方法的形式参数的个数.类型或顺序各不相 同,传回的值也可以不相同。

这种面向对彖程序特性称为()。

A )隐藏 B )覆盖 C )重载
D ) Java 不支持此特性
30. 对于构造函数,下列叙述不正确的是()。

A ) 构造函数也允许重载。

B ) 子类无条件地继承父类的无参构造函数。

28. 设有下面两个类的定义:
class Person { long id; //身份证号 String name; // 姓名
class Student extends Person int
score; //入学总分 int getScore(){ return score;
C )关联关系
D )无关系,上述类定义有语法错误
C)子类不允许调用父类的构造函数。

D)在同一个类屮定义的重载构造函数可以相互调用。

31.在使用interface声明一个接口时,只可以使用()修饰符修饰该接口。

A) private B) protected C) private protected D) public
32.在Java Applet程序用户自定义的Applet子类屮,常常重载()方法在Applet的界而屮显示文字、图形和
其它界面元素。

A) start() B) stop()
C) init() D ) paint()
33.在Java中,存放字符串常量的刈•象属于()类对象。

A) Character B) String
C) StringBuffer D) Vector
34.在Jav“图形用户界面编稈中,若显示一些不需要修改的文本信息,一般是使用()类的对象来实现。

A) Label B) Button C) TextArea D) TextField
35.创建一个标识有“关闭”按钮的语句是( )<>
A)TextField b = new TextField("关闭”);
B)Label b = new Label("关闭”);
C)Checkbox b = new Checkbox("关闭“);
D)Button b = new Button("关闭”);
36.在编写Java Applet程序时,若需要对发生的事件做出响应和处理,一般需要在程序的开头写上
( )语句。

A) import java.awt.* ; B) import java.applet.* ;
C) import java.io.*; D) import java.awt.event.* ;
37.当Frame改变大小时,放在其中的按钮大小不变,则使用如下哪个Layout?
A) FlowLayout B) CardLayout
C) BorderLayout E) GridLayout
38.哪个关键字可以抛出异常?
A) transient B) finally C) throw D) static
39.System类在哪个包中?
A) java.util B) java.io C) java.awt D) java」ang
40.以下哪个方法用于定义线程的执行体?
A) start() B) init() C) run() D) main()
二、读程序(每小题只有一个正确答案,每小题2分,共40分〉
1 ・ Give the code fragment:
if(x>4){
System.out.printlnC'Test 1");
}else if (x>9){
System.out.println(44Test 2 J;
}else {
System.out.println(44Test 3");
}
Which range of value x would produce of output “Test 2M?
A. x<4
B. x>4
C. x>9
D. None
2. Which correctly create an array of five empty Strings?
A.String a[] = new Stringl5J;
for (int i=0;iv5;a[i++]="”);
B.String a[5];
C.String ⑸ a;
D.String [J a = new String[5J;
for (int i = 0 ;i<5;a[i++] = null);
3- Given the following class definition: class A{
protected int i;
A(int i){
this.i=i;
}
}
which of the following would be a valid inner class for this class?
Select all valid answers:
A.class B{ }
B.class B extends A{ }
C.class B extends A{
B(){ System.out.println(44i=,,+i);}
}
D.class B{
class A{}
}
4. What happens when you try to compile and run the following program? class Mystery{
String s;
public static void main(String[] args){
Mystery m=new MysteryO;
m.go();
}
void Mystery(){
s=M c on structof\
void go(){
System.out.println(s);
A. this code will not compile
B・(his code runs and writes M nulF, in the standard output
C.this code runs but no thing appears in the standard output
D.this code runs and “constructor" in the standard output
5. Give the following class:
public class Example {
String str=new String(u good^);
char ch[]={
public static void main(String
argsl]){ Example ex=new Example();
ex.cha ngeCex.sgex.ch);
System.out.pri ntln(ex.str+^and^+ex.ch); }
public void change(String str^char
ch|]){ str=M test ok”;ch[0]='g';
}
}
Which is the output:
A. good and abc
C. test ok and abc
6.Give following class:
class AClassf
private long val;
public ACIass(long v){val=v;}
public static void main(String args[]){
AClass x=new ACIass(lOL);
AClass y=new AClass(lOL); AClass
z=y;
long a=10L;
int b=10;
}
}
Which expression result is true?
A. a==b;
B. a==x;
7.Give the following java class: B. good and gbc
D・ test ok and gbc
C. x==y;
D. a==10.0;
public class Example}
static int x[J=new int[15J;
public static void main(String args[]){ System.out.pri ntln(x[5]); }
}
Which statement is corrected?
A. When compile, some error will occur. C. Output is zero.
8・ Give the following java class:
public class Example}
public static void main(String args[]){ static int x[J = new int[15J; System.out.println(x[5J); }
}
Which statement is corrected?
A. When compile, some error will occur. C. Output is zero. 9. Given this class:
class Loop {
public static void main (String [] args){ int x=0; int y=0;
outer: for (x=0; x<100; x++) { middle: for (y=(); y<100; y++) {
System.out.println(n x=u + x + "; y=n + y); if(y==io ){
____________ }
}
1
}//main [//class
The question is which code must replace the __________ to finish (终止)the outer loop? A ・ continue middle; B. break outer;
C. break middle;
D ・ continue outer;
10. What is the output of the following code?
outer: for(int i=l; i<2; i++){ inner: for(int j=l; j<2; j++){
if(j=2){
B. When run, some error will occur. D. Output is nulL
B. When run, some error will occur. D. Output is null.
continue outer;
System.out.println(i + n and n + j);
}
}
A. 1 and 1
B. 1 and 2
C. 2 and 1
D. 2 and 2
11 ・ Give the code fragment:
1)switch(x){
2)case 1:System.out.printlnC'Test l n);break;
3)case 2:
4)case 3:System.out.println(u Test 2M);break;
5)default:System.out.println(“encT);
6)}
which value of x would cause "Test 2" to the output:
A. 1
B. 2
C. 4
D. default
12.The following code is entire contents of a file called Example.java,causes precisely one error during
compilation:
1)class SubClass extends BaseClass{
2)}
3)class BaseClass(){
4)String str;
5)public BaseClass(){
6)System.out.printlnC'ok^);)
7)public BaseClass(String s){
8)str=s;)}
9)public class Example}
10)public void method(){
11)SubClass s=new SubClass(<4hello M);
12)BaseClass b=new BaseClassC i world M);
13)}
14)}
Which line would be cause the error?
A. 9
B. 10
C. 11
D.12
13.Give the following code:
public class Example)
public static void main(String args[J ){
int 1=0;
do{
System.out.printlnC'Doing it for 1 is:"+l);
}while(—1>0)
System.out.printlnCTinish^);
Which well be output:
A. Doing it for 1 is 3
B. Doing it for I is 1
C. Doing it for 1 is 2
D. Doing it for I is 0 and Finish
14.What is the result of executing the following code:
public class Test {
int x=2;
inty;
public static void main(String args fl) {
int z=3;
Test t=new Test();
System.out.println(t.x+t.y+z);
}
}
A) 2 B) 3 C) 5 D) 12
15.What is the result of executing the following code:
public class Test {
public static void main(String args[]) {
A a=new A(u aaaaa n);
A.B b=a.new B();
System.out.pri ntln(b.inStr);
}
}
class A {
private String outStr;
public A(String s) {
outStr=s;
}
public class B {
public String inStr=n abcd";
}
}
A) aaaaa B) ababa C) abed D) aaaaaabed
16.下面的程序编译运行后,从键盘输入9,冋车后输出的结果是()o
import java.io.*;
public class Test {
public static void main(String argsf]) throws IOExceplion { BufferedReader buf=new BufferedReader(
new InputStreamReader(System.in)); while(true) {
String str=buf.readLine();
if(str.equals(n quit"))
break;
int x=lnteger.parselnt(str);
System.out.println(x *x);
}
1
}
A) 9 B) 81 C) quit D) 3
17•应用程序的main方法中有以下语句,则执行后输出的结果是()。

int[] x二{25, 2, 55, 68, 98};
int max=x[0];
for(int i=l; i<x.length; i++){
if(x[i]>max)
max=xfi];
}
System.out.println(min);
A) 12 B) 2 C) 98 D) 55
18.What is the result of executing the following code:
public class Test implements A {
int x=10;
public static void main(String args[]) {
Test c 1 = new Test();
System.out.println(cl.x+A.k);
1
}
interface A {
int k= 10;
A) 10 B) 0 C) 20 D) 100
19.What is the result of executing the following code:
public class Test {
public static void main(String args[]) {
X a=new X() {
public void showX() {
System.out.println(n yyyyy n);
}
};
a.showXQ;
)
}
class X {
public void showX() {
System.out.println(H xxxxx n);
}
}
A) yyyyy B) xxxxx C) xy D) xxxxxyyyyy
20.What is the result of executing the following code:
class Outer{ private int a;
void foo(double d,final float f){
String s;
final boolean b;
class Inner)
void methodlnner(){
System.out.println(H in the Inner11);
}
}
}
public static void main(String argsfl)
{
Outer me=new Outer();
me.foo( 123,234);
System.out.println(n outer u);
三、编程题(20分)
1. 输入两个正整数m和n,求其最大公约数和最小公倍数。

2. 输入一个正整数,判断它是不是回文数。

答题卷
单项选择题(广40每小题1分,共40分)
I二、读程序(广20每小题2分,共40分)
三、编程题(每小题10分,共20分)
1.
D|P
import java.util.*;
public class lianxi06
static void main(String[] args) { a ,b,m;
Scanner s = new Scanner(System.in);
System.out.print("键入一个整数:");
a = s.nextlnt();
System.out.print("再键入一个整数:"); b = s.nextlnt();
deff cd = new deff();
m = cd.deff(a,b);
int n = a * b / m;
System.out.println("最大公约数:” + m);
System.out.println(n最小公倍数:n + n);
}
}
class deff{
public int deff(int x, int y) { int t;
if(x < y){
t = x;
x = y;
y = t;
}
while(y != 0) {
if(x == y) return x;
else {
int k = x % y;
x = y;
y = k;
}
}
return x;
2.
import java.util.*;
public class lianxi25a {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
boolean is =true;
System.out.pnntC*请输入一个正整数:”);
long a = s.nextLongO;
String ss = Long.toString(a);
charf] ch = ss.toCharArrayO;
int j=ch.length;
for(int i=0; i<j/2; i++) {
if(ch[i]! =ch [j -i-1 ]) {is=false;}
}
if(is==true) {System.out.println(n这是一个回文数”);} else {System.out.println(n这不是一个回文数”); }。

相关文档
最新文档