admin 管理员组文章数量: 1086019
2024年3月20日发(作者:paas系统哪个公司做的最好)
班
级
学
号
姓
名
A卷
密
封
装
订
线
密
封
装
订
线
密
封
装
订
线
注意事项:
请将各题答案按编号顺序填写到答题卷上,答在试卷上无效。
一、单项选择题(
1~20每小题1分,21~30每小题2分,共40分)
1. Which are keywords in Java?
A. Null B. TRUE
2. Consider the following code:
Integer s = new Integer(9);
Integer t = new Integer(9);
Long u = new Long(9);
Which test would return true?
A. ((new Integer(9)) B. ((9))
C. (s==u) D. (s==t)
3. Which statement of assigning a long type variable to a hexadecimal value is correct?
A. long number = 345L; B. long number = 0345;
C. long number = 0345L; D. long number = 0x345L;
4. Which layout manager is used when the frame is resized the buttons's position in the
Frame might be changed?
A. BorderLayout B. FlowLayout C. CardLayout D. GridLayout
5. Which are not Java primitive types?
A. short B. Boolean C. byte D. float
6. Given the following code:
if (x>0) { n("first"); }
else if (x>-3) { n("second"); }
else { n("third"); }
Which range of x value would print the string "second"?
A. x > 0 B. x > -3 C. x <= -3 D. x <= 0 & x > -3
7. Given the following code:
public class Person{
int arr[] = new int[10];
public static void main(String a[]) {
n(arr[1]);
}
}
面向对象程序设计(JAVA) 第 1 页 共 18 页
C. sizeof D. implements
Which statement is correct?
A. When compilation some error will occur.
B. It is correct when compilation but will cause error when running.
C. The output is zero.
D. The output is null.
8. Short answer:
The decimal value of i is 13, the octal i value is:
A. 14 B. 015 C. 0x14 D. 012
9. A public member vairable called MAX_LENGTH which is int type, the value of the
variable remains constant value 100. Use a short statement to define the variable.
A. public int MAX_LENGTH=100; B. final int MAX_LENGTH=100;
C. final public int MAX_LENGTH=100; D. public final int MAX_LENGTH=100.
10. Which correctly create an array of five empty Strings?
A. String a [] = {"", "", "", "", "", ""}; B. String a [5]; C. String [5] a;
D. String [] a = new String[5]; for (int i = 0; i < 5; a[i++] = null);
11. Given the following method body:
{if (sometest()) {
unsafe();
}else {
safe();
}
}
The method "unsafe" might throw an IOException (which is not a subclass of
RunTimeException). Which correctly completes the method of declaration when added
at line one?
A. public void methodName() throws Exception
B. public void methodname()
C. public void methodName() throw IOException
D. public IOException methodName()
12. What would be the result of attempting to compile and run the following piece of code?
public class Test {
static int x;
public static void main(String args[]){
n("Value is " + x);
}
}
面向对象程序设计(JAVA) 第 2 页 共 18 页
A. The output "Value is 0" is printed.
B. An object of type NullPointerException is thrown.
C. A "possible reference before assignment" compiler error occurs.
D. An object of type ArrayIndexOutOfBoundsException is thrown.
13. What is the return-type of the methods that implement the MouseListener interface?
A. boolean B. Boolean C. void D. Point
14. Select valid identifier of Java:
A. #pass B. 3d_game C. $charge D. this
15. Given a TextField that is constructed like this:
TextField t = new TextField(30);
Which statement is true?
A. The displayed width is 30 columns.
B. The displayed string can use multiple fonts.
C. The displayed line will show exactly thirty characters.
D. The maximum number of characters in a line will be thirty.
16. Which declares an abstract method in an abstract Java class?
A. public abstract method(); B. public abstract void method();
C. public void abstract Method(}; D. public abstract void method() {}
17. What happens when this method is called with an input of "Java rules"?
1. public String addOK(String S) {
2. S += " OK!";
3. return S;
4. }
Select one correct answer
A. The method will return "Java rules OK!".
be thrown.
C. The method will return "OK!";
"Java rules".
18. Which of the following are Java keywords?
A. array B. boolean
B. A runtime exception will
D. The method will return
C. Integer D. Long
19. Assume that val has been defined as an int for the code below.
if(val > 4){
n("Test A");
}else if(val > 9){
n("Test B");
}
面向对象程序设计(JAVA) 第 3 页 共 18 页
else n("Test C");
Which values of val will result in "Test C" being printed:
A. val < 4 B. val between 4 and 9 C. val = 10 D. val > 9
20. Which of the following are valid definitions of an application's main ( ) method?
A. public static void main( ); B. public static void main( String args );
C. public static void main( String args [] ); D. public static void
main( Graphics g );
21. After the declaration:
char[] c = new char[100];
what is the value of c[50]?
A. 50 B. "" C. 'u0032' D. 'u0000'
22. Which of the following statements assigns "Hello Java" to the String variable s ?
A. String s = "Hello Java"; B. String s [] = "Hello Java";
C. new String s = "Hello Java"; D. String s[] = new String ("Hello
Java");
23. If arr[] contains only positive integer values, what does this function do?
public int guessWhat(int arr[]){
int x = 0;
for(int i = 0; i < ; i++)
x = x < arr[i] ? arr[i] : x;
return x;
}
A. Returns the index of the highest element in the array
B. Returns true/false if there are any elements that repeat in the array
C. Returns how many even numbers are in the array
D. Returns the highest element in the array
24. Which of the following are legal declarations of a two–dimensional array of integers?
A. int[5][5] a = new int[][]; B. int a = new int[5,5];
C. int a[][] = new int [5][5]; D. int[][]a = new [5]int[5];
25. If val = 1 in the code below:
switch (val){
case 1: ("P");
case 2:
case 3: ("Q") ;
break;
case 4: ("R");
面向对象程序设计(JAVA) 第 4 页 共 18 页
default: ("S");
}
A. P B. PQ C. QS
26. Given the following code:
1. public class Test {
2. int m, n;
3. public Test() { }
4. public Test(int a) { m=a; }
5. public static void main(String arg[]) {
6. Test t1,t2;
7. int j,k;
8. j=0; k=0;
9. t1=new Test();
10. t2=new Test(j,k);
11. }
12. }
Which line would cause one error during compilation?
A. line 3 B. line 5 C. line 6 D. line 10
27. For the code:
m = 0;
D. PQRS
while( ++m < 2 )
n(m);
Which of the following are printed to standard output?
A. 0 B. 1 C. 2 D. 3
28. Consider the following code: What will happen when you try to compile it?
public class InnerClass{
public static void main(String[]args){}
public class MyInner{ }
}
A. It will compile fine.
B. It will not compile, because you cannot have a public inner class.
C. It will compile fine, but you cannot add any methods, because then it will fail to
compile.
D. It will compile fail.
29. What is the result of executing the following code:
public class Test{
面向对象程序设计(JAVA) 第 5 页 共 18 页
public static void main(String args[]) {
String word = "restructure";
n(ing(2, 5));
}
}
A. rest B. es C. str D. st
30. What will be written to the standard output when the following program is run?
public class Test {
public static void main(String args[]) {
n(9 ^ 2);
}
}
A. 11 B. 7 C. 18
31. When call fact(3), What is the result?
int fact(int n){
if(n<=1)
return 1;
else
return n*fact(n-1);
}
A. 2 B. 6 C. 3
32. What is the result of executing the following code:
String s=new String("abcdefg");
for(int i=0;i<();i+=2){
((i));
}
A. aceg B. bdf C. abcdefg
33. What is the result of executing the following code:
public class Test {
public static void changeStr(String str){
str="welcome";
}
public static void main(String[] args) {
String str="12345";
changeStr(str);
n(str);
}
面向对象程序设计(JAVA) 第 6 页 共 18 页
D. 0
D. 0
D. abcd
}
Please write the output result :
A. welcome B. 12345 C. welcome12345 D. 12345welcome
34. What is the result of executing the following code:
1. public class Test {
2. static boolean foo(char c) {
3. (c);
4. return true;
5. }
6. public static void main( String[] argv ) {
7. int i =0;
8. for ( foo('A'); foo('B')&&(i<2); foo('C')){
9. i++ ;
10. foo('D');
12. }
13. }
14. }
What is the result?
A. ABDCBDCB B. ABCDABCD
C. Compilation fails. D. An exception is thrown at runtime.
35. What will happen when you attempt to compile and run the following code?
public final class Test4{
class Inner{
void test(){
if ();
else
sample();
}
}
private boolean flag=false;
public void sample(){
n("Sample");
}
public Test4(){
(new Inner()).test();
}
面向对象程序设计(JAVA) 第 7 页 共 18 页
public static void main(String args[]){
new Test4();
}
}
What is the result:
A. Print out “Sample”
B. Program produces no output but termiantes correctly.
C. Program does not terminate.
D. The program will not compile
36. What is the result of executing the following fragment of code:
class Base {
Base(){
amethod();
}
int i = 100;
public void amethod(){
n("d()");
}
}
public class Derived extends Base{
int i = -1;
public static void main(String argv[]) {
Base b = new Derived();
n(b.i);
d();
}
public void amethod() {
n("d()");
}
}
A. d() B. d()
-1 100
d() d()
C. 100 D. Compile time error
d()
37. What is the result of executing the following code:
面向对象程序设计(JAVA) 第 8 页 共 18 页
public class Test {
String s1="menu";
public static void main(String args[]) {
int z=2;
Test t=new Test();
n(t.s1+z);
}
}
A. menu2 B. 2 C. 2menu
38. What is the result of executing the following code:
public class Test implements A {
int x=5;
public static void main(String args[]) {
Test c1 = new Test();
n(c1.x+A.k);
}
}
interface A {
int k= 10;
}
A. 5 B. 10 C. 15
D. menu
D. 105
39. What is the result of executing the following code:
import ;
public class Test {
public static void main(String[] unused) {
String[] str = {"xxx", "zzz","yyy","aaa"};
(str);
int index=Search(str,"zzz");
if(index==-1)
n("no");
else
n("yes");
}
}
A. no B. xxx C. 0
40. What is the result of executing the following code:
D. yes
面向对象程序设计(JAVA) 第 9 页 共 18 页
int b[][]={{2, 3, 4}, {5, 6}, {7, 8}};
int sum=0;
for(int i=0;i<;i++) {
for(int j=0;j
sum+=b[i][j];
}
}
n("sum="+sum);
A. 9 B. 11 C. 15
41. What is the result of executing the following code:
public class Test{
static void leftshift(int i, int j){
i<<=j;
}
public static void main(String args[]){
int i=4, j=2;
leftshift(i,j);
n(i);
}
}
A. 2 B. 4 C. 8
42. What is the result of executing the following code:
public class Test {
int x=2;
int y;
public static void main(String args[]) {
int z=3;
Test t=new Test();
n(t.x+t.y+z);
}
}
A. 5 B. 23 C. 2
43. What is the result of executing the following fragment of code:
boolean flag = false;
if (flag = true) {
n("true");
面向对象程序设计(JAVA) 第 10 页 共 18 页
D. 35
D. 16
D. 3
} else {
n("false");
}
A. true B. false C. An exception is raised D. Nothing happens
44. In the following applet, how many buttons will be displayed?
import .*;
import .*;
public class Q16 extends Applet {
Button okButton = new Button("Ok");
public void init() {
add(okButton);
add(okButton);
add(okButton);
add(new Button("Cancel"));
add(new Button("Cancel"));
add(new Button("Cancel"));
add(new Button("Cancel"));
setSize(300,300);
}
}
A. 1 Button with label "Ok" and 1 Button with label "Cancel".
B. 1 Button with label "Ok" and 4 Buttons with label "Cancel".
C. 3 Buttons with label "Ok" and 1 Button with label "Cancel".
D. 4 Buttons with label "Ok" and 4 Buttons with label "Cancel".
45. What is the result of executing the following code:
1. class StaticStuff {
2. static int x = 10;
3. static { x += 5; }
4. public static void main(String args[]){
5. n("x = " + x);
6. }
7. static { x /= 5; }
8. }
A. x = 10 B. x = 15 C. x = 3 D. x=5
46. What will appear in the standard output when you run the Tester class?
class Tester {
面向对象程序设计(JAVA) 第 11 页 共 18 页
int var;
Tester(double var) {
= (int)var;
}
Tester(int var) {
this("hello");
}
Tester(String s) {
this();
n(s);
}
Tester() {
n("good-bye");
}
public static void main(String args[]) {
Tester t = new Tester(5);
}
}
A. "hello" B. "good-bye"
C. "hello" followed by "good-bye" D "good-bye" followed by "hello"
47. What letters are written to the standard output with the following code?
class Unchecked {
public static void main(String args[]){
try {
method();
} catch(Exception e) { }
}
static void method() {
try {
wrench();
n("a");
} catch(ArithmeticException e) {
n("b");
} finally {
n("c");
}
面向对象程序设计(JAVA) 第 12 页 共 18 页
n("d");
}
static void wrench() {
throw new NullPointerException();
}
}
Select all valid answers.
A. "a" B. "b" C. "c"
48. Given this code snippet:
try {
tryThis();
return;
} catch(IOException x1) {
n("exception 1");
return;
} catch(Exception x2) {
n("exception 2");
return;
} finally {
n("finally");
D. "d"
}
what will appear in the standard output if tryThis() throws a IOException?
A. "exception 1" followed by "finally"
B. "exception 2" followed by "finally"
C. "exception 1"
D. "exception 2"
二、填空题(每空1分,共10分)
1. JVM指的是Java【1】。
2. Java中的字符变量在内存中占【2】位(bit)。
3. Java语言对简单数据类型进行了类包装,int对应的包装类是【3】。
4. 继承性是面向对象方法的一个基本特征,它使代码可【4】
5. 抽象类中含有没有实现的方法,该类不能【5】。
6. 在Java的输入输出流中,数据从数据源流向数据目的地,流的传送是【6】行的。
7. 若类声明时加上修饰符 final ,则表示该类不能有【7】。
面向对象程序设计(JAVA) 第 13 页 共 18 页
8. Java的类库中提供Throwable类来描述异常,它有Error 和【8】两个直接子类。
9. 类中的某些方法通过类名就可以直接被调用,例如ssage
10. Java 的线程调度策略是一种基于优先级的【10】式调度。
Dialog(null,”按确定键退出”)中的showMessageDialog 方法,这种方法称为【9】。
三、写出下面程序的功能或运行结果(每小题4分,共20分)
1. 下面程序的功能是什么?
public class Exam1 {
public static void main(String[] args) {
for(int i=1; i<10; i++) {
for(int j=1; j<=i; j++) {
(j + "*" + i + "=" + j*i + " " );
if(j*i<10){(" ");}
}
n();
}
}
}
2. 下面程序的功能是什么?
public class Exam2 {
public static void main(String[] args) {
int x = 2, y = 1, t;
double sum = 0;
for(int i=1; i<=15; i++) {
sum = sum + (double)x/y;
t = y;
y = x;
x = y + t;
}
n("Sum=" + sum);
}
}
3. 下面程序的功能是什么?
import .*;
public class lianxi29 {
面向对象程序设计(JAVA) 第 14 页 共 18 页
public static void main(String[] args) {
Scanner s = new Scanner();
int[][] a = new int[3][3];
n("请输入9个整数:");
for(int i=0; i<3; i++) {
for(int j=0; j<3; j++) {
a[i][j] = t();
}
}
n("输入的3 * 3 矩阵是:");
for(int i=0; i<3; i++) {
for(int j=0; j<3; j++) {
(a[i][j] + " ");
}
n();
}
int sum = 0;
for(int i=0; i<3; i++) {
for(int j=0; j<3; j++) {
if(i == j) sum += a[i][j];
}
}
n("Sum=" + sum);
}
}
4. 下面程序运行时的输出为:
public class Test{
public static String output="";
public static void foo(int i){
try {
if(i==1){
throw new Exception();
}
output +="a";
}catch(Exception e){
output+="b";
面向对象程序设计(JAVA) 第 15 页 共 18 页
return;
}finally{
output+="c";
}
output+="d";
}
public static void main(String args[]){
foo(0);
foo(1);
n(output);
}
}
5. 下面程序运行时的输出为:
class Unchecked {
public static void main(String args[]){
try {
method();
} catch(Exception e) { }
}
static void method() {
try {
wrench();
n("a");
} catch(ArithmeticException e) {
n("b");
} finally {
n("c");
}
n("d");
}
static void wrench() {
throw new NullPointerException();
}
}
五、编程题(20分)
面向对象程序设计(JAVA)第 16 页 共 18 页
1.海滩上有一堆桃子,五只猴子来分。第一只猴子把这堆桃子凭据分为五份,
多了一个,这只猴子把多的一个扔入海中,拿走了一份。第二只猴子把剩
下的桃子又平均分成五份,又多了一个,它同样把多的一个扔入海中,拿
走了一份,第三、第四、第五只猴子都是这样做的,问海滩上原来最少有
多少个桃子? 。
2. 一个数如果恰好等于它的因子之和,这个数就称为 "完数 "。例如6=1+2
+3,编程找出1000以内的所有完数。
面向对象程序设计(JAVA) 第 17 页 共 18 页
班
级
学
号
姓
名
答题卷
一、单项选择题
(1~20每小题1分,21~35每小题2分,共50分)
密
封
装
订
线
密
封
装
订
线
密
封
装
订
线
1 2 3 4 5 6 7 8 9 10
20
30
11
21
12
22
13
23
14
24
15
25
16
26
17
27
18
28
19
29
二、填空题(每空1分,共10分)
1._________________ 2._________________
3._________________ 4._________________
5._________________ 6._________________
7._________________ 8._________________
9._________________ 10.________________
三、写出下面程序的运行结果(每小题4分,共20分)
面向对象程序设计(JAVA) 第 18 页 共 18 页
版权声明:本文标题:JAVA双语教学考试试卷及答案A 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/b/1710912565a579276.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论