JAVA考前模拟题与答案解析二

JAVA考前模拟题与答案解析二
JAVA考前模拟题与答案解析二

JAVA考前模拟题与答案解析(二)

JAVA试题及解答(二)2007-06-30 15

一、选择题

1、下面哪些是java语言中的关键字?

A sizeof

B abstract

C NULL

D Native

答:B

2、下面语句哪个是正确的?

A char='abc';

B long l=oxfff;

C float f=0.23;

D double=0.7E-3;

答:D

3、以下程序测试String 类的各种构造方法,试选出其运行效果。

class STR

{ public static void main(String args[])

{

String s1=new String();

String s2=new String("String 2");

char chars[]={'a',' ','s','t','r','i','n','g'};

String s3=new String(chars);

String s4=new String(chars,2,6);

byte bytes[]={0,1,2,3,4,5,6,7,8,9};

StringBuffer sb=new StringBuffer(s3);

String s5=new String(sb);

System.out.println("The String No.1 is "+s1);

System.out.println("The String No.2 is "+s2);

System.out.println("The String No.3 is "+s3);

System.out.println("The String No.4 is "+s4);

System.out.println("The String No.5 is "+s5);

}

}

A The String No.1 is The String No.2 is String 2 The String No.3 is a string

The String No.4 is string The String No.5 is a string

B The String No.1 is The String No.2 is String 2 The String No.3 is a string

The String No.4 is tring The String No.5 is a string

C The String No.1 is The String No.2 is String 2 The String No.3 is a string

The String No.4 is strin The String No.5 is a string

D 以上都不对

答:A

4、下面语句段的输出结果是什么?

int i = 9;

switch (i)

{ default:

System.out.println("default");

case 0:System.out.println("zero"); break;

case 1: System.out.println("one");

case 2: System.out.println("two");

}

A default

B default, zero

C error default clause not defined

D no output displayed

答:B

二、不定项选择题(在每小题的五个备选答案中选出正确答案,并将正确答案的序号填入题干后面的括号内,错

选多选,漏选均不得分。)

1、给出如下代码:

class Test

{

private int m;

public static void fun()

{ // some code...

}

}

如何使成员变量m 被函数fun()直接访问?

A、将private int m 改为protected int m

B、将private int m 改为public int m

C、将private int m 改为static int m

D、将private int m 改为int m

答: C

2、下面哪几个函数是public void example(){...}的重载函数?

A、public void example( int m){...}

B、public int example(){...}

C、public void example2(){...}

D、public int example ( int m, float f){...}

答: A,D

3、给出下面的代码段:

public class Base

{

int w,

x, y ,z;

public Base(int a,int b)

{ x=a; y=b;

}

public Base(int a, int b, int c, int d) { // assignment x=a, y=b w=d; z=c; }

}

在代码说明// assignment x=a, y=b处写入如下哪几个代码是正确的?

A、Base(a,b);

B、x=a, y=b;

C、x=a; y=b;

D、this(a,b);

答: C,D

4、已知如下定义:String s = "story"; 下面哪个表达式是合法的?

A、s += "books";

B、char c = s[1];

C、int len = s.length;

D、String t = s.toLowerCase();

答: A,D

5、Java中main()函数的值是什么?

A、String

B、int

C、char

D、void

答:D

6、如下哪些字串是Java中的标识符?

A、fieldname

B、super

C、3number

D、#number

E、$number

答:A,E

7、如下哪些是Java中有效的关键字?

A、const

B、NULL

C、false

D、this

E、native

答:A,C,D,E

8、如下哪些是Java中正确的整数表示?

A、22

B、0x22

C、022

D、22H

答: A,B,C

9、下面的代码段中,执行之后i 和j 的值是什么?

int i = 1;

int j;

j = i++;

A、1, 1

B、1, 2

C、2, 1

D、2, 2

答: C

10、下面句话是正确的?

A、>> 是算术右移操作符.

B、>> 是逻辑右移操作符.

C、>>> 是算术右移操作符

D、>>> 是逻辑右移操作符

答:A,D

11、下面哪个赋值语句是合法的?

A、float a = 2.0

B、double b = 2.0

C、int c = 2

D、long d = 2

答:B,C,D

12、下面哪个是main()函数的合法参数?

A、char args[]

B、char args[][]

C、String arg要[]

D、String args

答: C

13、下面哪个语句是创建数组的正确语句?

A、float f[][] = new float[6][6];

B、float []f[] = new float[6][6];

C、float f[][] = new float[][6];

D、float [][]f = new float[6][6];

E、float [][]f = new float[6][];

答:A,B,C,D

14、已知表达式int m[] = {0, 1, 2, 3, 4, 5, 6 }; 下面哪个表达式的值与数组下标量总数相等?

A、m.length()

B、m.length

C、m.length()+1

D、m.length+1

答:B

15、已知如下的命令执行java MyTest a b c 请问哪个语句是正确的?

A、args[0] = "MyTest a b c"

B、args[0] = "MyTest"

C、args[0] = "a"

D、args[1]= 'b'

答:C, D

16、已知如下代码:

public class Test

{

long a[] = new long[10];

public static void main ( String arg[] )

{ System.out.println ( a[6] );

}

}

请问哪个语句是正确的?

A、Output is null.

B、Output is 0.

C、When compile, some error will occur.

D、When running, some

error will occur.

答:B

17、已知如下代码:boolean m = true; if ( m == false ) System.out.println("False"); else

System.out.println("True"); 执行结果是什么?

A、False

B、True

C、None

D、An error will occur when running.

答: B

18、已知如下代码:public class Test { public static void main(String arg[]) { int i = 5; do {

System.out.println(i); } while (--i>5) System.out.println("finished"); } } 执行后的输出是什么? A

、 5 B、4 C

、6 D、Finished E、None

答:A,D

19、下面代码执行后的输出是什么?outer: for(int i=0;i<3; i++) inner: for(int j=0;j<2;j++) { if

(j==1) continue outer; System.out.println(j+ "and "+i); }

A、0 and 0

B、0 and 1

C、0 and 2

D、1 and 0

E、1 and 1

F、1 and 2

G、2 and 0

H、2 and 1

I、2

and 2

答:A,B,C

20、已知如下代码:switch (m) { case 0: System.out.println("Condition 0"); case 1:

System.out.println("Condition 1"); case 2: System.out.println("Condition 2"); case 3:

System.out.println("Condition 3");break; default: System.out.println("Other Condition"); } 当m 的

值为什么时输出"Condition 2"?

A、0

B、1

C、2

D、3

E、4

F、None

答:A,B,C

21、当浏览器返回到新URL的包含applet 的页面时调用以下哪个函数?

A、init()

B、start()

C、stop()

D、destroy() 答:B

22、以下哪个方法用于定义线程的执行体?A、start() B、init() C、run() D、main() E、synchronized()

答:C

23、Java中如下哪个约束符是正确的? A、private B、public C、protected D、protect E、friend 答:

A,B,C

24如果类中的成员变量可以被同一包访问,则使用如下哪个约束符? A、private B、public C、protected D

、no modifier E、final 答:D

25、以下哪个约束符可用于定义成员常量?A、static B、final C、abstract D、No modifier can be used

答:B

26、如下哪个语句正确说明了native方法? A、public native void test(); B、public native void test

(){} C、public void native test(); D、public native test(){} 答:A

27、已知如下类说明:public class Test { private float f = 1.0; int m = 12; static int n=1;

public static void main(String arg[]) { Test t = new Test(); // some code... } } 如下哪个使用是正

确的?A、t.f B、this.n C、Test.m D、Test.n 答:A,D

28、已知如下代码:1: class Example{ 2: String str; 3: public Example(){ 4: str= "example"; 5: }

6: public Example(String s){ 7: str=s; 8: } 9:} } 10: class Demo extends Example{ 11: } 12:

public class Test{ 13:public void f () { 14:Example ex = new Example("Good"); 15:Demo d = new

Demo("Good"); 16:} } 哪句语句会导致错误?A、line 3 B、line 6 C、line 10 D、line 14 E、line 15

答:E

29、已知如下类定义:class Base { public Base (){ //... } public Base ( int m ){ //... }

protected void fun( int n ){ //... } } public class Child extends Base{ // member methods } 如下

哪句可以正确地加入子类中?A、private void fun( int n ){ //...} B、void fun ( int n ){ //... } C

、protected void fun ( int n ) { //... } D、public void fun ( int n ) { //... } 答:C,D

30、如下哪个语句是正确的?A、In Java single inheritance is allowed, which makes code more

reliable. B、A subclass inherits all methods ( including the constructor ) from the superclass. C

、 A class can implement as many interfaces

as needed. D、When a class implements an interface,

it can define as many methods of the interface as needed. 答:A,C

31、在如下源代码文件Test.java中, 哪个是正确的类定义?

A、public class test { public int x = 0; public test(int x) { this.x = x; } }

B、public class Test{ public int x=0; public Test(int x) { this.x = x; } }

C、public class Test extends T1, T2 { public int x = 0; public Test (int x) { this.x = x; } }

D、public class Test extends T1{ public int x=0; public Test(int x){ this.x = x; } }

E、protected class Test extends T2{ public int x=0; public Test(int x){ this.x=x; } }

答:B,D

32、Person, Student 和Teacher 都是类名。这些类有以下继承关系。Person | --------------- | |

Student Teacher 并且在Java源代码中有如下表达式:Person p = new Student(); 如下哪个语句是正确的?

A、The expression is legal.

B、The expression is illegal.

C、Some errors will occur when compile.

D、Compile is correct but it will be wrong when running.

答:A

33、当Frame改变大小时,放在其中的按钮大小不变,则使用如下哪个layout?

A、FlowLayout

B、CardLayout

C、North and South of BorderLayout

D、East and West of BorderLayout

E、GridLayout 答:D

34、当Frame改变大小时,放在其中的按钮大小不变,则使用如下哪个layout? A、FlowLayout B、CardLayout

C、North and South of BorderLayout

D、East and West of BorderLayout

E、GridLayout 答:A

35、如下哪个方法可以从WindowEvent获取事件源? A、getFrame() B、getID() C、getSource() D、

getWindow() 答:C,D

36、以下哪个有关事件监听器的语句是正确的?A、Multiple listeners can be attached to one

component. B、Only one listener can be attached to one component. C、One listener can receive and

process the events from multiple components. D、One listener can receive and process the events

from only one component. 答:A,C

37、监听器接口的方法返回值是什么?A、int B、String C、void D、Object E、AWTEvent 答:C

38、下面哪个事件监听器在Java中有事件适配器? A、MouseListener B、KeyListener C、ActionListener D

、ItemListener E、WindowListener 答:A,B,E

39、下面哪个方法与applet的显示无关? A、update() B、draw() C、repaint() D、paint() 答:B

40、已知如下说明:TextArea ta = new TextArea ("Hello", 5, 5); 请问哪个语句是正确的?

A、The

maximum number of characters in a line is 5. B、The displayed height is 5 lines otherwise constrain. C、The displayed string can use multiple fonts. D、The displayed strings are editable.

答:B,D

41、请问如下哪个方法可以将MenuBar加入Frame中? A、setMenu() B、setMenuBar() C、add() D、

addMenuBar() 答:B

42、下面哪个不是Java中的容器? A、ScrollPane B、Canvas C、Scrollbar D、Applet E、Dialog 答:B,C

43、下

面哪个方法可用于定义新线程类?

A、implement the Runnable interface

B、add a run() method in the class

C、create an instance of Thread

D、extend the Thread class

答:A,D

44、下面哪个stream是node流?

A、FileInputStream

B、BufferedInputStream

C、PushbackInputStream

D、ByteArrayInputStream 答:A,D

45、哪个类可用于处理Unicode? A、InputStreamReader B、BufferedReader C、Writer D、

PipedInputStream 答:A,B

46、下面哪些语句能够正确地生成5个空字符串? A String a[]=new String[5]; for(int

i=0;i<5;a[++]

=""); B String a[]={"","","","",""}; C String a[5]; D String[5]a; E String []a=new String[5];

for( int i=0;i<5;a[i++]=null);

答:A,B

47、下面哪些选项将是下述程序的输出?public class Outer{ public static void main(String

args[]){ Outer: for(int i=0; i<3; i++) inner:for(int j=0;j<3;j++){ if(j>1)

break; System.out.println(j+"and"+i); } } } A 0 and 0 B 0 and 1 C 0 and 2 D 0

and 3 E 2 and 2 F 2 and 1 G 2 and 0

答:A,B,C

48、下面哪个语句正确地声明一个整型的二维数组?

A int a[][] = new int[][];

B int a[10][10] = new int[][];

C int a[][] = new int[10][10];

D int [][]a = new int[10][10];

E int []a[] = new int[10][10];

答:C,D,E

三、编程题1、编写一个程序,用选择法对数组a[]={20,10,50,40,30,70,60,80,90,100}进行从大到小的排序

。编程题答案

public class ArraySort

{

public static void main(String args[])

{

int array[]={20,10,50,40,30,70,60,80,90,100};

int i,j,k,t;

int l=array.length;

for(i=0;i

{

k=i;

for(j=i+1;j

if(array[j]

t=array[k];array[k]=array;array=t;

}

for(i=0;i

System.out.println("array["+i+"]="+array);

}

}

《JAVA语言程序设计》期末考试试题及答案(2)

《JA V A语言程序设计》期末考试试题及答案 一、单选题 1、下列程序段执行后的结果是( A )。 String s = new String("abcdefg"); for (int i=0; i

java模拟试题附答案(一)

scjp模拟试题(一) Question No: 1 1.public class test ( 2. public static void main (String args[]) { 3. int i = 0xFFFFFFF1; 4. int j = ~i; 5. 6. } 7. ) What is the decimal value of j at line 5? A. 0 B. 1 C. 14 D. –15 E. An error at line 3 causes compilation to fail. F. An error at line 4 causes compilation to fail. 答案: C Question No: 2 Given: Integer i = new Integer (42); Long 1 = new Long (42); Double d = new Double (42.0); Which two expressions evaluate to True? (Choose Two) A. (i ==1) B. (i == d) C. (d == 1) D. (i.equals (d))

E. (d.equals (i)) F. (i.equals (42)) 答案: D, E Question No: 3 Exhibit : 1. public class test ( 2. private static int j = 0; 3. 4. private static boolean methodB(int k) ( 5. j += k; 6. return true; 6. ) 7. 8. public static void methodA(int i) { 9. boolean b: 10. b = i < 10 | methodB (4); 11. b = i < 10 || methodB (8); 12. } 13. 14. public static void main (String args[] ) ( 15. methodA (0); 16. system.out.printIn(j); 17. ) 18. ) What is the result? A. The program prints “0” B. The program prints “4” C. The program prints “8”

《JAVA语言程序设计》期末考试试题及答案2(应考必备题库)

《JA V A语言程序设计》期末考试试题及答案2(应考必备题库) 一.判断题 1.Java的源代码中定义几个类,编译结果就生成几个以.class为后缀的字节码文件。(√)2.Java程序里,创建新的类对象用关键字new,回收无用的类对象使用关键字free。(×)3.Java有垃圾回收机制,内存回收程序可在指定的时间释放内存对象。(×) 4.构造函数用于创建类的实例对象,构造函数名应与类名相同,返回类型为void。(×)5.在异常处理中,若try中的代码可能产生多种异常则可以对应多个catch语句,若catch 中的参数类型有父类子类关系,此时应该将父类放在后面,子类放在前面。(√) 6.拥有abstract方法的类是抽象类,但抽象类中可以没有abstract方法。(√)7.Java的屏幕坐标是以像素为单位,容器的左下角被确定为坐标的起点。(×) 8.静态初始化器是在其所属的类加载内存时由系统自动调用执行。(√) 9.在Java中对象可以赋值,只要使用赋值号(等号)即可,相当于生成了一个各属性与赋值对象相同的新对象。(×) 二.单项选择题 1.Java application中的主类需包含main方法,以下哪项是main方法的正确形参?() A、String args B、String ar[] C、Char arg D、StringBuffer args[] 2.以下关于继承的叙述正确的是()。 A、在Java中类只允许单一继承 B、在Java中一个类只能实现一个接口 C、在Java中一个类不能同时继承一个类和实现一个接口 D、在Java中接口只允许单一继承 3.paint()方法使用哪种类型的参数?() A、Graphics B、Graphics2D C、String D、Color 4.以下哪个不是Java的原始数据类型() A、int B、Boolean C、float D、char 5.以下哪项可能包含菜单条()。 A、Panel B、Frame C、Applet D、Dialog

java模拟试卷3与答案

复习题 3 一、选择题 1. JDK 提供的编译器是(B)。 (A ) java.exe(B ) javac.exe (C) javap.exe( D) javaw.exe 2.以下作为 Java 程序入口的 main 方法声明正确的( C)。 (A ) public void main(String args[]) (B ) public int main(String args[]) (C) public static void main(String args[]) (D ) public static int main(String args[]) 3.以下标识符错误的是( C )。 (A )Public( B)张三( C) class(D ) main 4.java 中定义字符串 String s= ”pzhu”,下面操作可以取得字符串长度的是( A )。 (A ) s.length()( B) s.length( C)s.size()( D) length(s) 5.如下定义数组,操作正确的是(D)。 int a[]={1,2,3}; (A ) a[3]=100(B ) a[0].length( C)a++( D) a.length 6.如下定义二维数组操作错误的是()。 int a[][]={{1,2},{3}}; (A ) a[0][1]=200( B) a[0].length( C) a[1][1]=100( D) a.length 7. 以下数据类型存储空间最大的是(B)。 (A ) byte( B) long(C) float(D ) char 8. 面向对象的三大特性,不包括如下( A)。 (A )异常( B)封装(C)继承(D )多态 9、关于类的定义以下说法错误(B)。 (A )类定义使用class 关键字( B)每个类中必须有一个main 方法 (C)一个包可以包含多个类( D) java 中所有类都是Object 类的子类 10. 关于构造方法以下说法错误的是(D)。 (A)构造方法名必须与类名一致(B)构造方法可以重载 (C)构造方法是通过new 来调用(D)每个类都必须编写构造方法代码 11.关于继承如下说法错误的是(C)。 (A) Java 是单继承的(B)通过extends 来定义继承 (C)所有父类方法都可以被override的(D)继承呈现的是 is a 的关系 12.以下代码执行的结果是 ( C )。 System.out.println(" 攀枝花学院 pzhu".length()); (A)编译错误(B)运行错误(C) 9(D) 14 13. 用来存储键值对的容器是 ()。 (A )ArrayList( B ) LinkedList(C) HashSet( D) HashMap 14、 java 中用来抛出异常的关键字是( C )。 (A) try(B) catch(C) throw(D) throws 15.关于 finally块中的代码,以下说法不正确的是(A)。 (A ) try 块中的 return 语句会中断finally 块中语句的执行 (B )无论 finally 块前的语句运行是否产生异常,其中的语句都会执行 (C) finally 块中的语句通常中用作资源的清理 - 1 -

大学java期末试卷2份(含答案)

Java大学考试试卷 一、选择题(每题2分,共30分) 1、Java中main()函数的值是。 A、 String B、int C、char D、void 2、如下字串是Java中的标识符。 A、 fieldname B、super C、3number D、#number 3、下面的代码段中,执行之后i 和j 的值是。 int i = 1; int j; j = i++; A、 1, 1 B、1, 2 C、2, 1 D、2, 2 4、已知表达式int m[] = {0, 1, 2, 3, 4, 5, 6 };下面表达式的值与数组下标量总数相等。 A、 m.length() B、m.length C、m.length()+1 D、m.length+1 5、当浏览器返回到新URL的包含applet 的页面时调用以下函数。 A、 init() B、start() C、stop() D、destroy() 6、以下方法用于定义线程的执行体。 A、 start() B、init() C、run() D、main() 7、如果类中的成员变量可以被同一包访问,则使用如下约束符。 A、 private B、public C、protected D、final 8、以下约束符可用于定义成员常量。 A、 static B、final C、abstract D、No modifier can be used 9、下面方法与applet的显示无关。 A、 update() B、draw() C、repaint() D、paint() 10、请问如下方法可以将MenuBar加入Frame中。 A、 setMenu() B、setMenuBar() C、add() D、addMenuBar() 11、下面不是Java中的容器。 A、 ScrollPane B、Canvas C、Dialog D、Applet 12、下面的程序段创建了BufferedReader类的对象in,以便读取本机d盘my文件夹下的文件1.txt。File 构造函数中正确的路径和文件名的表示是。 File f=new File(填代码处); file=new FileReader(f); in=new BufferedReader(file); A) "1.txt" B) "d:\\my\\1" C) "d:\\my\\1.txt" D) "d:\ my\1.txt" 13、有整型数组:int[] x={12,35,8,7,2};,则调用方法Arrays.sort(x)后,数组x中的元素值依次是。A) 2 7 8 12 35 B) 12 35 8 7 2 C) 35 12 8 7 2 D) 8 7 12 35 2 14、下面的程序段执行后输出的结果是。 StringBuffer buf=new StringBuffer("Beijing2008"); buf.insert(7,"@"); System.out.println(buf.toString()); A) Beijing@2008B) @Beijing2008 C) Beijing2008@ D) Beijing#2008 15、.下面表达式可用得到x和y的最大值。 A) x>y?y:x B) xy?(x+y):(x-y) D) x==y?y:x; 二、多选题(每题至少有一个正确答案,多选少选都不给分,每题2分,共10分) 16、下面赋值语句是合法的。 A、float a = 2.0 B、double b = 2.0 C、int c = 2 D、long d = 2 17、下面语句是创建数组的正确语句。 A、 float f[][] = new float[6][6]; B、float []f[] = new float[6][6]; C、float f[][] = new float[][6]; D、float [][]f = new float[6][6]; 18、Java中如下约束符是正确的。 A、 private B、public C、protected D、protect 19. 下面事件监听器在Java中有事件适配器。 A、 MouseListener B、KeyListener C、ActionListener D、WindowListener 20、已知如下的命令执行 java MyTest a b c,语句是正确的。 A、 args[0] = "MyTest a b c" B、args[0] = "MyTest" C、args[0] = "a" D、args[1]= 'b' 填空题(每空格2分,共20分) 1. 创建类的对象时,使用运算符__________给对象分配内存空间。 2. 定义类的构造方法不能有返回值类型,其名称与____ _名相同。

java三级模拟试卷及答案

Java三级考试时间3小时 理论知识 基本概念 一、单选,20题,每题1分,满分20分 二、多选,35题,每题2分,满分70分 三、判断,10题,每题1分,满分10分 应用操作 一、单选,20题,每题3分,满分60分 二、多选,5题,每题4分,满分20分 三、填空,5题,每题4分,满分20分 操作技能 试题1 65分 试题2 35分 计算机程序设计员(java)(三级)理论知识试卷基本概念试卷 注意事项 考试时间:40min。 请首先按要求在试卷的标封处填写您的姓名、准考证号和所在单位的名称。请仔细阅读各种题目的回答要求,在规定位置填写您的答案。 不要在试卷上乱写乱画,不要在标封区填写无关的内容。

得分 评分人一、单项选择题(第1题~第 20题。选择一个正确的答案,将相应的字母填入题内的 括号中。每题1分,满分20分) 1. 下面关于JA VA 的说法中,哪个是错误的?() A. Java 是一种完全面向对象的程序设计语言 B. Java 支持goto 语句 C. Java 提供了许多机制来保证程序的健壮性和安全性 D. Java 是一门可以跨平台的语言 2. 若要编写一个类Hello ,下列说法中哪个是错误的?() A. 源代码文件必须叫做Hello.java 或者hello.java ,否则编译出错 B. 编译后生成的二进制码文件为Hello.class C. 运行的命令为java Hello D. 若将文件Hello.class 改名为hello.class ,那么用命令java hello 也可以运行 3. 下面哪个不是Java 的基本数据类型?() byte A. B. char String C.boolean D.

JAVA试题_2

JAVA试题 一、选择 1.MAX_LENGTH是int型public成员变量,变量值保持为常量100,用简短语句定义这个变量。 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. 2.给出下面代码: 1)class Parent{ 2)private String name; 3)public Parent(){} 4)}5)public class Child extends Parent{ 6)private String department; 7)public Child(){} 8)public String getValue(){return name;} 9)public static void main(String arg[]){ 10)Parent p=new Parent(); 11)}12)} 哪些行将引起错误? A第3行B第6行C第7行D第8行 3.类Teacher和Student是类Person的子类; Person p; Teacher t; Student s; //p,t and s are all non-null. if(t instanceof Person){s=(Student)t;} 最后一句语句的结果是: A将构造一个Student对象;B表达式是合法的; C表达式是错误的;D编译时正确,但运行时错误。 4.给出下面代码段 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)} 哪行将引起一个编译时错误?

JAVA模拟试题(含答案)

一、请分别写出下面程序的运行结果,将答案添在每道题后的空格处 1. public class Test1 { public static void main(String[] args) { int x=10,y=20; System.out.print("x="+(x++)+" y="+(++y)+" sum="+(x+y)); } } 运行结果:x=10 y=21 sum=32 2. public class Test2 { public static void main(String[] args) { boolean end; for(int i=2;i<20;i++){ end=true; for(int j=2;j<=i;j++){ if(i%j==0&&j

2.Java基础知识测试和答案讲解

单选题:(每道题目2分) 1. 下列哪个声明是错误的?(B) A. int i=10; B. float f=1.1; C. double d=34.4; D. byte b=127; 2. 下面哪个不是java中的关键字?(C) A. public B. true C. main D. class 3. 下面程序哪个语句是正确的C A. byte a=0,b=3; byte c =a+b; B. short s =23; s=s+12; C. short s=23; s+=12; D. float f = 23+23.23; 4. 下面程序执行的结果是?(B) class Test { public static void main(String[] args) { System.out.println(“”+‘a’+1); } } A. 98 B. a1 C. 971 D. 197 5. 下面程序执行的结果是?(B) int i = 100; while(true) { if (i++ > 100) { break; } System.out.println(i);

} A. 100 B. 101 C. 102 D. 报错 6. 下面程序的运行结果是 ( D ) int a=3, b=1; if(a==b) { System.out.println("a="+a); } A. a=1 B. a=3 C. 编译错误 D. 正常运行但没有输出 7. 下面程序的运行后,结果正确的是:B int a=1,b=2; int c=(a+b>3?a++:++b); A. a=2,b=3 B. a=1,b=3 C. a=1,b=2 D. c=2 8. 下面程序的运行结果B class Demo { public static int fun(int c) { return c+=2; } public static void main(String[] args) { int temp = fun(2); System.out.println(temp); } } A. 2 B. 4 C. 6 D. 8 9. 下面数组定义错误的是(C)

蓝桥杯java模拟试题

本试卷包含两种题型:“代码填空”与“程序设计”。 填空题要求参赛选手在弄清给定代码工作原理的基础上填写缺失的部分,使得程序逻辑正确、完整。所填写的代码不多于一条语句(即不能出现分号)。 编程题要求选手设计的程序对于给定的输入能给出正确的输出结果。注意:在评卷时使用的输入数据与试卷中给出的实例数据可能是不同的。选手的程序必须是通用的,不能只对试卷中给定的数据有效。1.代码填空(满分3分) 以下程序打印出0~9的数字,请补充缺少的代码。 public class MyTest { public static void f(int begin, int end) { __________________; System.out.println(begin); f(begin+1, end); } public static void main(String[] args) { f(0,9); } } if(begin>end) return;//相当于退出循环的条件。return 无返回值根据void 2.代码填空(满分4分) 如果要把两个整型变量a、b的值交换,一般要采用一个中间变量做过渡,但也可以在不借助任何其它变量的情况下完成。试填写缺失的代码。 a = a ^ b; b = _________; a = _________; a^b a^b 3.代码填空(满分3分) 许多人都曾经玩过“拍七”游戏。规则是:大家依次从1开始顺序数数,数到含有7或7的倍数的要拍手或其它规定的方式表示越过(比如:7,14,17,71等都不能数出),下一人继续数下面的数字。违反规则者受罚。下面的程序模拟这个过程,拍7的情况输出“*”,请完善之。 for(int i=1; i<100; i++) { if(i % 7 == 0) System.out.println("*"); else if(___________________) System.out.println("*"); else System.out.println(i); } (i-7)%10==0||i/10==7 // i/10==7||i%10==7 4.代码填空(满分5分)

java模拟试卷及答案及解析1

复习题1 一、选择题 1.以下程序的输出结果是( A ) int x=010, y=10, z=0x10; System.out.println(x+ " "+y+ " "+z); A)8 10 16 B)8 10 10 C)10 10 10 D)8,10,16 2.选出以下定义合法的标识符:( D ) A)float b)2ac C)#3c D)$abc 3.下面程序的运行结果是( A ) int i=5; System.out.print( i++); System.out.print (i--); System.out.print (--i); System.out.print (i--); A)5644 B)6543 C)6654 D)5654 4.对整型变量a=16,b=5,下列表达式的值为true的是( D )A)!(b==a/3) B)b!=a%11 C)a>1&&b<1 D)!=b||a>b 5.下列选项中,合法的String型字符串常量是( D ) A)’M’ B)How are you C)’#apple’D)"apple" 6.设int a=15,则运行a+=a运算后,a的值是( D ) A)0 B)15 C)225 D)30 7.以下程序的输出结果是( B ) int x=3,y=6; System.out.print (x/y);

A)0 B)0.5 C)2 D)错误信息 8.能将容器划分为"East"、 "South"、"West"、"North"、"Center"五个区域的布局管理器是( A ) A)BorderLayout B)FlowLayout C)GridLayout D)CardLayout 9.在以下程序中,显示的数字一共有( C )个。 int i; for(i=0; i<10; i++) { if(i%2==0) continue; System.out.println(i); } 1,3,5,7,9 A)10 B)11 C)5 D)4 10.当if…..else 嵌套时,else总是与( D )配对使用。 A)同一行的if B)同一列的if C)在它前面最近的if D)在它前面最近且未配对的if 11.下列数组定义中,正确的是( C ) A)int a[][]=new int [10,10]; B)int a[10][10]; C)int a[][]=new int [10][10]; D)int a[][10]; 12.以下程序的运行结果为( B )

java模拟试题(带答案)

判断题 1.Java语言中的数组元素下标总是从0开始,下标可以是整数或整型表达式。 (√)2.在Java中对象可以赋值,只要使用赋值号(等号)即可,相当于生成了一 个各属性与赋值对象相同的新对象。(×) 3.所谓抽象类就是包含有抽象方法的类。(×) 4.Java系统的标准输入对象是System.in,标准输出对象有两个,分别是标准 输出System.out和标准错误输出System.err。(√)5.如果p是父类Parent的对象,而c是子类Child的对象,则语句c = p是 正确的。(×)6.当一个方法在运行过程中产生一个异常,则这个方法会终止,但是整个程序 不一定终止运行。(√) 7.用“+”可以实现字符串的拼接,用- 可以从一个字符串中去除一个字符子串。 (×) 8.一个容器中可以混合使用多种布局策略。(×) 9.Java中,并非每个事件类都只对应一个事件。(√) 10.Java的源代码中定义几个类,编译结果就生成几个以.class为后缀的字节 码文件。(√) 11.Java Applet是由独立的解释器程序来运行的。(×) 12.Java的字符类型采用的是ASCII编码。(×) 13.Java的各种数据类型占用固定长度,与具体的软硬件平台环境无关。(√) 14.System类不能实例化,即不能创建System类的对象。(×) 15.用户自定义的图形界面元素也可以响应用户的动作,具有交互功能。(√)填空题 1 java 源程序编译命令是 javac 2 java 应用程序中有一个main()方法,它前面有三个修饰符是 public , static , void 3 java语言数据类型可分为两大类,一类称为基本数据类型 ,另一类称为引用数据类型 4 在转向语句中, continue 语句使得程序结束本次循环,回到循环的条件测试部分继续执行。 5设x为float型变量, y为 double型变量, a为 int型变量,已知 x=2.5f,a=7 ,y=4.22 则表达式x+a%3*(int)x%(int)y的值为 4.5 6设x为float型变量, y为 double型变量, a为 int型变量,b 为long 型变量,c为char 型,则表达式x+y*a/x+b/y+c 的值为 double 类型 7设有数组定义:int MyIntArray[ ] = { 10 , 20 , 30 , 40 , 50 , 60 , 70}; 则执行以下几个语句后的输出结果是 120 。 int s = 0 ;

java模拟试卷及答案及解析4

复习题4 一、选择题 1.在面向对象的方法中,一个对象请求另一个对象为其服务的方式是通过发送( D ) A、调用语句 B、命令 C、口令 D、消息 2.Java语言具有许多优点和特点,下列选项中,哪个反映了Java程序并行机制的特点:( B ) A、安全性 B、多线程 C、跨平台 D、可移值 3.编写和运行Java applet程序与编写和运行Java application程序不同的步骤是:( B ) A、编写源代码 B、编写HTML文件调用该小程序,以.html为扩展名存入相同文件夹 C、编译过程 D、解释执行

4.Java的字符类型采用的是Unicode编码方案,每个Unicode码占用____个比特位。( B ) A、8 B、16 C、32 D、64 5.关于下列程序段的输出结果,说法正确的是:( D ) public class MyClass{ static int i; public static void main(String argv[]){ System.out.println(i); } } A、有错误,变量i没有初始化。 B、null C、1 D、0 6.下列代码的执行结果是:( B ) public class Test3{ public static void main(String args[]){ System.out.print(100%3);

. System.out.print(","); System.out.println(100%3.0); } } A、1,1 B、1,

C、1.0,1 D、1.0,1.0 7.下列程序段的输出结果是:( B ) void complicatedexpression_r(){ int x=20, y=30; boolean b; b=x>50&&y>60||x>50&&y<-60||x<-50&&y>60||x<-50&&y<-60; System.out.println(b); } A、true B、false C、1 D、0 8.给出下列代码片段:( D ) if(x>0){System.out.println("first");} else if(x>-3){ System.out.println("second");} else {System.out.println("third");} 请问x处于什么范围时将打印字符串“second”? A、x>0 B、x>

JAVA程序设计练习测试题及参考答案

第一部分 《Java 程序设计》练习测试 [说明]:要求所有答案务必写在答题纸的相应题号位置上,否则不予评分。 一、单选择题(共10分,每小题2分) 1、编译Java Application 源程序文件将产生相应的字节码文件,这些字节码文件的扩展 名为()。 A .class B .html C .java D .exe 2、设int x = 1 , y = 2 , z = 3; 则表达式y+=z- -/++x 的值是() 。 A 3 B 3. 5 C 4 D 5 3、在Java Applet 程序用户自定义的Applet子类中,一般需要重载父类的()方法 来完成一些画图操作。 A start( ) B stop( ) C in it( ) D pai nt() 4、不允许作为类及类成员的访问控制符的是()。 A public B static C private D protected 5、为AB类的一个无形式参数无返回值的方法method书写方法头,使得使用类名AB作为 前缀就可以调用它,该方法头的形式为()。 A final void method( ); B public void method(); C static void method( ); D abstract void method(); 二、填空题(共20分,每空格1分) 1、开发与运行Java程序需要经过的三个主要步骤为_(1)_、_⑵—和。 2、如果一个Java Applet 源程序文件只定义有一个类,该类的类名为MyApplet,则类MyApplet必须是一⑷一类的子类并且存储该源程序文件的文件名为一⑸一。 3、如果一个Java Applet 程序文件中定义有4个类,则使用Sun公司的JDK编译器一⑹ 编译该源程序文件将产生」7)_个文件名与类名相同而扩展名为―⑻― 的字节码文件。 4、在Java的基本数据类型中,char型采用Unicode编码方案,每个Unicode码占用_⑼ 字节内存空间,这样,无论是中文字符还是英文字符,都是占用_(10)_ 字节内存空间。 5、设int y = 5; 则表达式(y++ )/6 的值是_(11)_ 。 6、若int x = 5,y = 10; 则x= y 的逻辑值分别为_(12) ______ 和_(13)_ 。 7、_(14)_方法是一种仅有方法头,没有具体方法体和操作实现的方法,该方法必须在抽 象类之中定义。_(15)_ 方法是不能被当前类的子类重新定义的方法。 8、创建一个名为MyPackage的包的语句是_(16)_,该语句应该放在程序的位置为:_(17)_ 9、设有数组定义:int a[ ] = { 20 ,30 ,40 ,50 , 60 , 70 , 80,90,100,110,120,130}; 则执行以下几个语句后的输出结果是—(18)—。 int s =0; for( int i =0; i < a.len gth ; i ++) if( i%4==0) s +=a[i]; System.out.pri ntl n( s); 10、在Java程序中,通过类的定义只能实现_(19)_ 重继承,但通过接口的定义可以实 现_(20)_重继承关系。

JAVA试题及答案(50道选择题)

选择题 1、JAVA所定义的版本中不包括:( D ) A、JAVA2 EE B、JAVA2 Card C、JAVA2 ME D、J AVA2 HE E、J AVA2 SE 2、下列说法正确的是( A ) A、JAVA程序的main方法必须写在类里面 B、JAVA程序中可以有多个main方法 C、JAVA程序中类名必须与文件名一样 D、J AVA程序的main方法中如果只有一条语句,可以不用{}(大括号)括 起来 3、变量命名规范说法正确的是( B ) A、变量由字母、下划线、数字、$符号随意组成; B、变量不能以数字作为开头; C、A和a在java中是同一个变量; D、不同类型的变量,可以起相同的名字; 4、下列javaDoc注释正确的是( C ) A、/*我爱北京天安门*/ B、//我爱北京天安门*/ C、/**我爱北京天安门*/ D、/*我爱北京天安门**/ 5、为一个boolean类型变量赋值时,可以使用( B )方式 A、boolean = 1; B、boolean a = (9 >= 10); C、boolean a="真"; D、b oolean a = = false; 6、以下( C )不是合法的标识符 A、STRING B、x3x; C、void D、d e$f 7、表达式(11+3*8)/4%3的值是( D ) A、31 B、0 C、1

D、2 8、( A )表达式不可以作为循环条件 A、i++; B、i>5; C、bEqual = str.equals("q"); D、c ount = = i; 9、运算符优先级别排序正确的是(A ) A、由高向低分别是:()、!、算术运算符、关系运算符、逻辑运算符、 赋值运算符; B、由高向低分别是:()、关系运算符、算术运算符、赋值运算符、!、 逻辑运算符; C、由高向低分别是:()、算术运算符、逻辑运算符、关系运算符、!、 赋值运算符; D、由高向低分别是:()、!、关系运算符、赋值运算符、算术运算符、 逻辑运算符; 10、以下程序的运行结果是:( B ) public class Increment{ public static void main(String args[]) { int a; a = 6; System.out.print(a); System.out.print(a++); System.out.print(a); } } A.666 B.667 C.677 D.676 11、下列值不为true的表达式有( C )。 A、"john" = = "john" B、"john".equals("john") C、"john" = "john" D、"john".equals(new String("john")) 12、下列输出结果是( C ) int a = 0 ; while ( a < 5 ) { switch(a){ case 0:

相关文档
最新文档