文档库 最新最全的文档下载
当前位置:文档库 › Java 认证模考试题

Java 认证模考试题

Java 认证模考试题
Java 认证模考试题

Java 认证模考试题

[作者:佚名发表时间:2004-5-27 22:14:08 阅读:331 ]

Java 2 TEST

Question: 1

Given the following code:

class Test{

private int m;

public static void fun() {

// some code...

}

}

How can the member variable m be accessible directly in the method fun()?

A. change private int m to protected int m

B. change private int m to public int m

C. change private int m to static int m

D. change private int m to int m

Explanation:

If the variable m is changed to be a static variable it can be accessible in the method fun() for this method is a static member method.

Correct Answer: C 1 of 60

Question: 2

Which methods are correct overloading methods of the following method:

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){...}

Explanation:

The overloading methods must have the same names. If only the return type of the methods are different it is

sufficient tell the methods from each other. The arguments of the methods must be different enough to determine which method to call.

Correct Answer: A,D 2 of 60

Question: 3

Given the following fragment of code:

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;

}

Which expressions can be used at the point of // assignment x=a, y=b?

A. Base(a,b);

B. x=a, y=b;

C. x=a; y=b;

D. this(a,b);

Explanation:

In the second constructor, the call this(a,b) passes control the version of the constructor that takes two int arguments.

Correct Answer: C,D 3 of 60

Question: 4

Given the following definition:

String s = story;

Which of the following expressions are legal?

A. s += books;

B. char c = s[1];

C. int len = s.length;

D. String t = s.toLowerCase();

Explanation:

Answer B is not correct for String is a class and can'T be treated as an array of char. Answer C is not correct for s.length() should be used, not s.length.

Correct Answer: A,D 4 of 60

Question: 5

What is the return value of the main() method in Java?

A. String

B. int

C. char

D. void

Explanation:

The main() method in Java returns void.

Correct Answer: D 5 of 60

Question: 6

Which are the valid identifiers in Java?

A. fieldname

B. super

C. 3number

D. #number

E. $number

Explanation:

Valid identifiers in Java can start with a letter, underscore (_), or dollar sign ($), but not with digits or other signs. And identifiers can not be keywords.

Correct Answer: A,E 6 of 60

Question: 7

Which are valid Java keywords?

A. const

B. NULL

C. false

D. this

E. native

Explanation:

All the keywords in Java are lowercase. goto and const are keywords that are not used in Java programming language.

Correct Answer: A,C,D,E 7 of 60

Question: 8

Which are valid integral expressions in Java?

A. 22

B. 0x22

C. 022

D. 22H

Explanation:

In Java integral has three forms: decimal, octal and hexadecimal. Octal values start with a zero and hexadecimal values start with 0x.

Correct Answer: A,B,C 8 of 60

Question: 9

Which one of the following ranges of short is correct?

Explanation:

The length of the short data is 16 bits. The range of short is

The length of the short data is 16 bits. The range of short is

Correct Answer: D 9 of 60

Question: 10

Which one of the following ranges of byte is correct?

Correct Answer: B 10 of 60

Question: 11

Given the following fragment of code, what are results of i and j after execution? int i = 1;

int j;

j = i++;

A. 1, 1

B. 1, 2

C. 2, 1

D. 2, 2

Explanation:

Pay attention to the position of the operator ++. In this question, first j is assigned to 1, then the value of i is added to 2.

Correct Answer: C 11 of 60

Question: 12

Which of the following statements are true?

A. >> is the arithmetic right shift operator.

B. >> is the logical right shift operator.

C. >>> is the arithmetic right shift operator.

D. >>> is the logical right shift operator.

Explanation:

There are two right shift operators in Java. They are >> and >>>. >> is the arithmetic(signed) right shift operator and >>> is the logical(unsigned) right shift operator.

Correct Answer: A,D 12 of 60

Question: 13

Which of the following assignments are legal?

A. float a = 2.0

B. double b = 2.0

C. int c = 2

D. long d = 2

Explanation:

In Java the default data type of floating point is double, not float. The assignment from double to float requires an explicit cast.

Correct Answer: B,C,D 13 of 60

Question: 14

Which one of the following arguments is the correct argument of the main() method?

A. char args[]

B. char args[][]

C. String arg[]

D. String args

Explanation:

The argument of the main() method is an array of String. Then only answer C is an array of String.

Correct Answer: C 14 of 60

Question: 15

Which one of the following is correct to create an array?

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][];

Explanation:

In Java the declaration format allows the square brackets to be at the left or right of the variable name. But the new float[][6] is illegal.

Correct Answer: A,B,D,E 15 of 60

Question: 16

Given the following expression: int m[] = {0, 1, 2, 3, 4, 5, 6 };

Which result of the following expressions equals to the number of the array elements?

A. m.length()

B. m.length

C. m.length()+1

D. m.length+1

Explanation:

The number of elements in an array is stored in the length attribute in the array object. Correct Answer: B 16 of 60

Question: 17

Given the following command to run a correct class: java MyTest a b c

Which statements are true?

A. args[0] = MyTest a b c

B. args[0] = MyTest

C. args[0] = a

D. args[1]= 'b'

Explanation:

The three arguments a b c are stored in the args[] array of the main() method. Then args[0]= a, args[1]= b, args[2]= c.

Correct Answer: C 17 of 60

Question: 18

Given the following code:

public class Test{

long a[] = new long[10];

public static void main ( String arg[] ) {

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

}

}

Which statement is true?

A. Output is null.

B. Output is 0.

C. When compile, some error will occur.

D. When running, some error will occur.

Explanation:

When an array is created the members of the array is initialized. In this case all the elements are initialized to be 0. Correct Answer: B 18 of 60

Question: 19

Given the following fragment of code:

boolean m = true;

if ( m = false )

System.out.println(False);

else

System.out.println(True);

What is the result of the execution?

A. False

B. True

C. None

D. An error will occur when running.

Explanation:

= is the assignment operator. == is the compare operator. In this question the value of false is assigned to the variable m.

Correct Answer: A 19 of 60

Question: 20

Given the following code:

public class Test{

public static void main(String arg[]){

int i = 5;

do {

System.out.println(i);

} while (--i>5)

System.out.println(“finished”);

}

}

What will be output after execution?

A. 5

B. 4

C. 6

D. Finished

E. None

Explanation:

The expressions in the block of do/while loop will be executed at least once. If the condition of this loop is not met the loop will stop after once execution, otherwise, it will continue to loop until the condition is no met.

Correct Answer: A,D 20 of 60

Question: 21

What will be output after execution of the following code: 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

Explanation:

The continue statement is used to skip over and jump to the end of the loop body. Then if j equals to 1 it will jump to the end of the inner loop body.

Correct Answer: A,B,C 21 of 60

Question: 22

Given the following code:

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);

}

Which values of m will cause Condition 2 is output?

A. 0

JAVA期末考试试卷

天津城市建设学院2007~2008学年第二学期 《 java 语言程序设计A 》 试题A 卷 课程号:073101-0 试卷说明:闭卷考试,时间120分钟。 一、 填空(本题共15空,每空2分,共30分) 1.如果一个java 源程序文件中定义有4个类,使用sun 公司的JDK 编译器javac 编译该源程序文件将产生_____4___个文件名与类名相同扩展名为___.Class_____的字节码文件。 2.Java 中所有类都是类 __Object__的子类。 3.请填出在java .lang 包中与下列基本数据类型相对应的封装类: float :java .lang .Float , char : _ java .Lang.char_______, boolean : ___ java .Lang.boolean_____。 4.被关键字____final______修饰的方法是不能被当前类的子类重新定义的方法 5.线程的四种状态是__新建_____ 、_运行_ 、_中断 、__死亡___。 6.java 语言中__https://www.wendangku.net/doc/185217998.html,ng.Objet ___是所有类的根。 7.Swing 的事件处理机制包括__事件的监听者__、事件和事件处理者。 8.URL_____Uniform Resourse Locator_____是的缩写。 9.java 有两类应用程序java Application 和____java 10.转义字符以___\__开头。 二、选择(本题共20小题,每题2分,共40分) 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'; } } B 、 good and abc B 、 good and gbc C 、test ok and abc D 、 test ok and gbc 5.运行下列程序, 会产生什么结果 ( A )

JAVA程序设计期末考试题(多套含答案)

《JA V A程序设计》期末考试试题(五) 一、单选题 1、当某一线程正处于休眠状态,而另一个线程用Thread 类中的interrupt() 方法中断它时,抛出的异常类型是()。 A) IOException B) RuntimeException C) InterruptedException D) ClassNotFoundException 2、下面的程序段的功能是( )。 File file1=new File("d:\\xxx\\yyy\\zzz"); file1.mkdirs(); A)在当前目录下生成子目录:\xxx\yyy\zzz B)生成目录:e:\xxx\yyy\zzz C)在当前目录下生成文件xxx.yyy.zzz D)以上说法都不对 3、应用程序的main方法中有以下语句,则输出的结果是( )。 String s = "xxxxxxxxxxxxxxx#123#456#zzzzz"; int n = s.indexOf("#"); int k = s.indexOf("#", n+1); String s2 = s.substring(n+1, k); System.out.println(s2); A) 123456 B) 123 C) xxxxxxxxxxxxxxx D) zzzzz 4、关于下面的程序Test.java说法正确的是( )。 public class Test { String x="1"; int y; public static void main(String args[]) { int z=2; System.out.println(x+y+z); } } A)3 B)102 C) 12 D)程序有编译错误 5、应用程序的main方法中有以下语句,则输出的结果是( )。

java考试练习题

输出结果? int x = 0; int y = 10; do { y--; ++x; } while (x < 5); System.out.print(x + "," + y); 输出结果? public class Test { public static void main(String [] args) { int x = 4; boolean b1 = true; boolean b2 = false; if (!b2 && (x == 4)) System.out.print(“A"); else System.out.print(“B"); System.out.println(“C"); if ((b2 = true) && !b2) System.out.print(“D"); } } 输出结果? class Base { Base() { System.out.print("Base"); } } public class Alpha extends Base { public static void main(String[] args) { Alpha a = new Alpha(); Base b = new Base(); } }

输出结果? 在声明一个接口方法的时候下面哪些选项是合法的声明( ) A. void m (); B. public void m (); C. private void m (); D. final public void m (); E. static public void m (); 下面哪些不是java的关键字 ( ) A.float B. private C. void D. else E.String 下列哪个选项是合法的标识符 ( ) A.1_e B.S_Str C.class D.2second main()方法中有代码:Frame a=new Frame(“hello"); 为在屏幕上显示该对象,应加下面哪条语句( )。 A.a.appear(true) B.a.setForeground(true) C.a.setVisible(true) D.a.enable 下列哪个选项是创建一个标识有"关闭"按钮的语句。()A.TextField b = new TextField("关闭"); B.Button b = new Button("关闭"); C.Checkbox b = new Checkbox("关闭"); D.TextArea b = new TextArea ("关闭"); 在编写Java application程序时,若需要使用到标准输入输出语句,必须在程序的开头写上哪条语句()。 A. import java.awt.*; B. import java.io.*; C. import java.applet.applet; D. import java.awt.Graphics; 下列的哪个赋值语句是不正确的()。 A. float f = 11.1; B. double d = 5.3E12; C. float d = 3.14f ; D. double f=11.1E10f; JDK中运行Java小程序的命令是()。 A. javadoc B. appletviewer C. javac D. java 执行完语句int [] x = new int [25];后,则下列哪项说法是正确的() A.x[24]值为0 B.x[24]值未定义 C.x[25]值为0 D.x[0]值为空 Java中使用https://www.wendangku.net/doc/185217998.html,ng包中的___________类来创建一个字符串变量,因此字

Java期末考试试卷答案A

JAVA程序设计试卷库(第5套) 一、单选题(每小题 2 分,共 20 分) 1、Java Application源程序的主类是指包含有( A )方法的类。 A. main方法 B. toString方法 C. init方法 D. actionPerfromed方法 2、分析下面的程序段,下面的哪个描述是正确的。( B ) char mychar=’c’; switch(mychar){ default: case ‘a’“a”);break; case ‘b’“b”);break; } A.switch语句块是错误的, 因为switch后面的表达式 值的类型不是整数; B.switch语句块是正确的; C.switch语句块是错误的, 因为default没有放在语 句块的最后面; D.代码运行时,没有任何输出 结果。 3、编译并运行下面的Java程序, 将产生( B )结果。 class A{ int var1=1; int var2; public static void main(String[] args){ int var3=3; A a=new A(); } } A. 0 B. 4 C. 3 D. 代码无法编译,因为var2根本 没有被初始化 4、在Java中,下面关于包的陈述 中正确的是( D )。

A. 包的声明必须是源文件的任意位置; B. 包的声明必须紧跟在import 语句的后面; C. 只有公共类才能放在包中; D. 可以将多个源文件中的类放在同一个包中 5、 在Java 语言中,当一个类的某个变量声明为protected 时下列说法正确的是( C )。 A. 只有同一类中的成员才能访问它; B. 不同包中的任何其他类都能够访问它; C. 同包中的任何其他类能够访问它; D. 不同包中的子类不可以访问该变量。 6、在Java 中,执行下面的语句后,c 的值为( D )。 String s= "Jessica "; char c=s.charAt(6); A. "c " B. "a " C. 'c ' D. 'a ' 7、设有下面两个赋值语句: a = Integer.parseInt(“1024”); b = Integer.valueOf(“1024”).int Value(); 下述说法正确的是( D )。 A .a 是整数类型变量,b 是整数类对象。 B .a 是整数类对象,b 是整数类型变量。 C .a 和b 都是整数类对象并且它们的值相等。 D .a 和b 都是整数类型变量并且它们的值相等。 8、事件剪裁类如WindowAdapter (它实现了WindowListener 接

java期末考试试题及答案

1.谈谈final, finally, finalize的区别。 final关键字: a) 如果一个类被声明为final,意味着它不能再派生出新的子类,不能作为父类被继承。因此一个类不能既被声明为abstract的,又被声明为final的。 b) 将变量或方法声明为final,可以保证它们在使用中不被改变。 c) 被声明为final的变量必须在声明时给定初值,而在以后的引用中只能读取,不可修改。 d) 被声明为final的方法也同样只能使用,不能重载。 finally关键字:在异常处理时提供finally 块来执行任何清除操作。如果抛出一个异常,那么相匹配的catch 子句就会执行,然后控制就会进入finally 块。 finalize:方法名,不是关键字。Java技术允许使用finalize() 方法在垃圾收集器将对象从内存中清除出去之前做必要的清理工作。这个方法是由垃圾收集器在确定这个对象没有被引用时对这个对象调用的。它是在Object 类中定义的,因此所有的类都继承了它。子类覆盖finalize() 方法以整理系统资源或者执行其他清理工作。finalize()方法是在垃圾收集器删除对象之前对这个对象调用的。 2.GC是什么? 为什么要有GC? GC是垃圾收集器。Java 程序员不用担心内存管理,因为垃圾收集器会自动进行管理。要请求垃圾收集,可以调用下面的方法之一: System.gc() Runtime.getRuntime().gc() 3.Math.round(11.5)等於多少? Math.round(-11.5)等於多少? 写程序Math.round(11.5) = 12 Math.round(-11.5) = -11 4.给我一个你最常见到的runtime exception ArithmeticException, ArrayStoreException, BufferOverflowException, BufferUnderflowException, CannotRedoException, CannotUndoException, ClassCastException, CMMException, ConcurrentModificationException, DOMException, EmptyStackException, IllegalArgumentException, IllegalMonitorStateException, IllegalPathStateException, IllegalStateException, ImagingOpException, IndexOutOfBoundsException, MissingResourceException, NegativeArraySizeException, NoSuchElementException, NullPointerException, ProfileDataException, ProviderException, RasterFormatException, SecurityException, SystemException, UndeclaredThrowableException, UnmodifiableSetException, UnsupportedOperationException

Java语言练习题库(含答案)

单选题 1. 为了保证方法的线程安全,声明方法的时候必须用哪个修饰符? (A) new (B) transient (C) void (D) synchronized 2. 编译Java源文件使用哪个? (A) javac (B) jdb (C) javadoc (D) junit 3. 哪一种类的对象中包含有Internet地址。 (A) Applet (B) Datagramsocket (C) InetAddress (D) AppletContext 4. 有关GUI容器叙述,不正确的是? (A) 容器是一种特殊的组件,它可用来放置其它组件 (B) 容器是组成GUI所必需的元素 (C) 容器是一种特殊的组件,它可被放置在其它容器中

(D) 容器是一种特殊的组件,它可被放置在任何组件中 5. 使用javadoc生成的文档的文件格式是? (A) XML格式 (B) 自定义格式 (C) 二进制格式 (D) HTML格式 6. 下列有关类、对象和实例的叙述,正确的是哪一项? (A) 类就是对象,对象就是类,实例是对象的另一个名称,三者没有差别 (B) 对象是类的抽象,类是对象的具体化,实例是对象的另一个名称 (C) 类是对象的抽象,对象是类的具体化,实例是类的另一个名称 (D) 类是对象的抽象,对象是类的具体化,实例是对象的另一个名称 7. 在事件委托类的继承体系中,最高层次的类是哪项? (A) java.util.EventListener (B) java.util.EventObject (C) java.awt.AWTEvent (D) java.awt.event.AWTEvent 8. Java语言中异常的分类是哪项? (A) 运行时异常和异常 (B) 受检异常和非受检异常

SunJava程序员认证考试题

第一部分 基础知识练习 目标 本章对应于《学生指南》各章的内容分别提供了练习题集,包括: ●第一章Java入门 ●第二章数据类型和运算符 ●第三章流程控制与数组 ●第四章封装 ●第五章继承 ●第六章抽象类与接口 ●第七章多态 ●第八章异常 ●第九章多线程机制 ●第十章输入输出流 ●第十一章使用泛型和集合框架 ●第十二章基于Swing的图形用户界面(GUI)设计 ●第十三章Java事件驱动编程

第一章练习题(Java入门) 1.下列哪项不是JDK所包含的内容?(选一项)A.Java编程语言 B.工具及工具的API C.Java EE扩展API D.Java平台虚拟机 2.下列关于JDK、JRE和JVM的描述。哪项正确?A.JDK中包含了JRE,JVM中包含了JRE B.JRE中包含了JDK,JDK中包含了JVM C.JRE中包含了JDK,JVM中包含了JRE D.JDK中包含了JRE,JRE中包含了JVM 3.下列哪个工具可以编译java源文件?A.javac B.jdb C.javadoc D.junit 4.JDK工具javadoc的作用是哪项? A.生成Java文档 B.编译Java源文件 C.执行Java类文件

D.测试Java代码 5.以下哪些包是Java标准库中常用的包?(选三项)A.java.lang B.javax.servlet .http C.j ava. io D.java.sql

6.使用JDK工具生成的Java文档的文件格式是? A.XML格式 B.自定义格式 c.二进制格式 D.HTML格式 7.以下关于JVM的叙述,哪项正确?(选两项) A.JVM运行于操作系统之上,它依赖于操作系统 B.JVM运行于操作系统之上,它与操作系统无关 C.JVM支持Java程序运行,它能够直接运行Java字节码文件D.JVM支持Java程序运行,它能够直接运行Java源代码文件 8.以下关于支持Java运行平台的叙述,哪项错误? A.Java可在Solaris平台上运行 B.Java可在Windows平台上运行 C.Java语言与平台无关。Java程序的运行结果依赖于操作系统D.Java语言与平台无关。Java程序的运行结果与操作系统无关 9.以下关于Applet和Java程序之间关系的叙述,哪项错误?A.-个Applet就是一段Java程序 B.Applet是一种特殊的Java程序,它需要运行在Web服务器上C.Applet是一种特殊的Java程序,它需要运行在Web浏览器上

Java期末考试题

2010年——2011年Java期末考试题 一、判断题。 1.Java语言是平台无关的语言。T 2.类的静态方法中可以访问该类的非静态数据成员.F 3.Java中方法调用时参数传递都是按值传递的,因此从方法中退出时,参数的值是不 会变的。T 4.覆盖方法所抛出的异常不能比原方法更多。T 5.Final 方法不能被覆盖。T 6.抽象类中一定包含抽象方法。F 7.接口中的方法必须是抽象方法。T 8.在方法定义中,所以可能发生的异常都必须用try{} catch(){}捕捉。F 9.Java支持多重继承。F 10.Final修饰的类不能派生子类。T 11.覆盖的同名方法中,子类方法不能比父类方法的访问权限更严格。T 12.不能在静态方法中使用this.T 13.抽象类中不能创建对象。T 14.一个类可以实现多接口。T 15.接口中可以包含非静态成员。F 16.不论是否捕捉到异常try{}catch(){} final{}语句中finally块中的代码总要被执行。T 17.一个类实现一个接口,则该类必须实现接口中的所有方法。F 18.线程使用sleep方法去休眠后可以使用notify方法唤醒。F 19.线程使用sleep方法休眠是会释放该线程同步锁定的对象。F 20.Final类中的属性和方法都必须是final的。F 二、选择题 1、Java中复合数据类型不包括(D) A.类类型 B.数组 C.接口类型 D.指针 2、请从四个选项中选择答案,下列代码的执行结果是:(C) Public class Test{ Public static void main(String args[]){ Float t=9.0f; Int q=6; System.out.println((t++)*(--q)); } } A.40 B.40.0 C.45.0 D.36.0 3、下列关于修饰符混用的说法,错误的是(D) A.abstract 不能与final 并列修饰同一个类 B.abstract类中可以有非abstract的方法 C.普通类(非abstract类)中不能有abstract方法 D.static方法中能处理非static的属性 4、关于被保护访问控制符protected修饰的成员变量,以下说法正确的是(A) A.可以被该类自身、与它在同一个包中的其它类、在其它包中的该类的子类所访问B.只能被该类本身和该类的所有的子类访问 C.只能被该类自身所访问 D.只能被同一个包中的类访问 5、x=2,y=3,z=4,则表达式z*=y++*--x的值是(A) A.12 B.24 C.16 D.3 6、以下赋值语句正确的是(D) A.char c1=”a” B.float f1=3.22 C.byte b1=266 D.long L1=0xAC8L 7、Java不支持多重继承,但我们可以通过(B)实现 A.多态 B.接口 C.覆盖 D.抽象类 8.已知类person是类student的父类,以下数组定义和赋值哪些是正确的(A) A. person p[]=new person[3]; p[1]=new student(); B .student s[]=new person[3]; s[1]=new person(); C .person p[]= new student[3];p[1]= new person(); D .student s[]=new student[3];s[1]=new person; 9 编译MyClass.java之后,得到了三个字节码文件:MyClass.class , MyClasslittle$.class MyClass$1.class.这表明(C) A.MyClass类中的两个方法:little和1 B. MyClass.Java中有三个类:MyClass、little和1 C. MyClass类中有两个内部类:一个是命名的little,另一个是匿名的1 D. MyClass、little和1,这三者没什么关系 10、main 方法是java Application 程序执行的入口点,关于main方法的方法头以下(B)是合法的。 A.public static void main() B.public static void main(String arg[]) C.public static int main(String[] arg) D. B.public void main(String arg[]) 11、当编译和运行下面的代码会出现什么情况?(A)

JAVA期末考试复习试题

JAVA期末考试复习试题 JAVA期末考试复习试题 1.使用Java语言编写的源程序保存时的文件扩展名是()。(A).class (B).java (C).cpp (D).txt 2.设int a=-2,则表达式a>>>3的值为()。(A)0 (B)3 (C)8 (D)-1 3.设有数组的定义int[] a = new int[3],则下面对数组元素的引用错误的是()。(A)a[0]; (B)a[a.length-1]; (C)a[3]; (D)int i=1; a[i]; 4.在类的定义中可以有两个同名函数,这种现象称为函数()。(A)封装(B)继承(C)覆盖(D)重载5.在类的定义中构造函数的作用是()。(A)保护成员变量(B)读取类的成员变量(C)描述类的 特征(D)初始化成员变量6.下面关键字中,哪一个不 是用于异常处理语句()。(A)try (B)break (C)catch (D)finally 7.类与对象的关系是()。 (A)类是对象的`抽象(B)对象是类的抽象(C)对象 是类的子类(D)类是对象的具体实例8.下面哪一个是Java中不合法的标识符()。(A)$persons (B)twoNum (C)_myVar (D)*point 9.为AB类的一个无形

式参数无返回值的方法method书写方法头,使得使用类名AB 作为前缀就可以调用它,该方法头的形式为( )。(A)static void method( ) (B)public void method( ) (C)final void method( ) (D)abstract void method( ) 10.欲构造ArrayList类的一个实例,此类继承了List接 口,下列哪个方法是正确的()。(A)ArrayList myList=new Object( ) (B)List myList=new ArrayList( ) (C)ArrayList myList=new List( ) (D)List myList=new List( ) 11.Java源文件和编译后的文件扩展名分别为 ()(A) .class和 .java (B).java和 .class (C).class和 .class (D) .java和 .java 12.在Java Applet程序用户自定义的Applet子类中,一般需要重载父类 的( )方法来完成一些画图操作。(A) start( ) (B) stop( ) (C) init( ) (D) paint( ) 13.对于一个Java源文件,import, class定义以及package正确的顺序是: (A) package,import,class (B) class,import,package (C) import,package,class (D) package,class,import 14.下面哪个是非法的:(A) int I = 32; (B) float f = 45.0; (C) double d = 45.0; (D) char c = ‘u’; //符号错15.Java语言使用的字符码集是(A) ASCII (B) BCD (C) DCB (D) Unicode 16. 如果一个类的成员变量只能在

java期末考试复习题及答案

《Java程序设计》课程试卷 1.使用Java语言编写的源程序保存时的文件扩展名是( B )。 (A).class (B).java (C).cpp (D).txt 2.设int a=-2,则表达式a>>>3的值为( C )。 (A)0 (B)3 (C)8 (D)-1 3.设有数组的定义int[] a = new int[3],则下面对数组元素的引用错误的是( C )。 (A)a[0]; (B)a[a.length-1]; (C)a[3]; (D)int i=1; a[i]; 4.在类的定义中可以有两个同名函数,这种现象称为函数( D )。 (A)封装(B)继承(C)覆盖(D)重载 5.在类的定义中构造函数的作用是( D )。 (A)保护成员变量(B)读取类的成员变量(C)描述类的特征(D)初始化成员变量 6.下面关键字中,哪一个不是用于异常处理语句( B )。 (A)try (B)break (C)catch (D)finally 7.类与对象的关系是( A )。 (A)类是对象的抽象(B)对象是类的抽象(C)对象是类的子类(D)类是对象的具体实例 8.下面哪一个是Java中不合法的标识符( D )。 (A)$persons (B)twoNum (C)_myVar (D)*point 9.为AB类的一个无形式参数无返回值的方法method书写方法头,使得使用类名AB作为前缀就可以调用它,该方法头的形式为( A )。 (A)static void method( ) (B)public void method( ) (C)final void method( ) (D)abstract void method( ) 10.欲构造ArrayList类的一个实例,此类继承了List接口,下列哪个方法是正确的( C )。 (A)ArrayList myList=new Object( ) (B)List myList=new ArrayList( ) (C)ArrayList myList=new List( ) (D)List myList=new List( ) 11.Java源文件和编译后的文件扩展名分别为( B ) (A) .class和 .java (B).java和 .class (C).class和 .class (D) .java和 .java

java考证试题

一、单选题(共计60题) (1)下列有关事件监听器的描述正确的是()。 A、一个监听器只能接受一个组件产生的事件 B、只有一个监听器可以被附加到一个组件上 C、多个监听器可以被附加到一个组件 D、以上描述都不对 (2)当下列程序执行时,其输出结果是()。 A、2k B、7k C、-7k D、-3k (3)下列关于修饰符混用的说法错误的是()。 A、abstract不能与final并列修饰同一个类 B、staic方法中能处理非static的属性 C、abstract方法必须在abstract类中 D、abstract类中不可以有private的成员 (4)下列容器是从java.awt.W indow继承的是()。 A、Applet B、Panel C、Container D、Frame (5)关于构造方法,下列叙述错误的是()。 A、构造方法是类的一种特殊方法,它的方法名必须与类名相同 B、构造方法的返回类型只能是void型,且书写格式是在方法名前加void前缀 C、构造方法的主要作用是完成对类的对象的初始化工作 D、一般在创建新对象时,系统会自动调用构造方法 (6)下面2个文件位于相同目录下,编译运行后会出现的情况是()。 //File P1.java package MyPackage; class P1{ void afancymethod(){ Sy stem.out.println("What a fancy method"); } } //File P2.java public class P2 extends P1{ public static void main(String argv[]){ P2 p2 = new P2();

JAVA期末考试考卷及答案

《J A V A语言程序设计》期末考试模拟试题 一、单选择题(每小题2分,共10分) 1、编译Java Application 源程序文件将产生相应的字节码文件,这些字节码文件的扩展 名为( B )。 A. .java B. .class C. .html D. .exe 2、设 x = 1 , y = 2 , z = 3,则表达式 y+=z--/++x 的值是( A )。 A. 3 B. 3. 5 C. 4 D. 5 3、在Java Applet程序用户自定义的Applet子类中,一般需要重载父类的( D )方 法来完成一些画图操作。 A. start( ) B. stop( ) C. init( ) D. paint( ) 4、不允许作为类及类成员的访问控制符的是( C )。 A. public B. private C. static D. protected 5、为AB类的一个无形式参数无返回值的方法method书写方法头,使得使用类名AB作为 前缀就可以调用它,该方法头的形式为( A )。 A. static void method( ) B. public void method( ) C. final void method( ) D. abstract void method( ) 二、填空题(每空格1分,共20分) 1、开发与运行Java程序需要经过的三个主要步骤为编辑源程序、 编译生成字节码和解释运行字节码。

MyApplet必须是 Applet 类的子类并且存储该源程序文件的文件名为MyApplet 。 3、如果一个Java Applet程序文件中定义有3个类,则使用Sun公司的JDK编译 器编译该源程序文件将产生 3 个文件名与类名相同而扩展名为 . class 的字节码文件。 4、在Java的基本数据类型中,char型采用Unicode编码方案,每个Unicode码占 用 2 字节内存空间,这样,无论是中文字符还是英文字符,都是占 用 2 字节内存空间。 5、设 x = 2 ,则表达式 ( x + + )/3 的值是 1 。 6、若x = 5,y = 10,则x < y和x >= y的逻辑值分别为 true 和 false 。 7、抽象(abstract)方法方法是一种仅有方法头,没有具体方法体和操作实现的方法,该方法必须在抽象类之中定义。最终(final)方法方法是不能被当前类的子类重新定义的方法。 8、创建一个名为 MyPackage 的包的语句是 package MyPackag , 该语句应该放在程序的位置为:应该在程序第一句。 9、设有数组定义:int MyIntArray[ ] = { 10 , 20 , 30 , 40 , 50 , 60 , 70}; 则执行以下几个语句后的输出结果是 120 。 int s = 0 ; for ( int i = 0 ; i < ; i + + ) if ( i % 2 = = 1 ) s += MyIntArray[i] ; 10、在Java程序中,通过类的定义只能实现单重继承,但通过接口的定义可以实现多重继承关系。

JAVA考试复习题(附答案)

《现代程序设计》(JAVA)考试复习题 一、选择题 1、关于Java语言叙述错误的是:(C) A.Java语言具有跨平台性B.Java是一种面向对象的语言 C.Java语言中的类可以多继承D.Java的垃圾收集机制自动回收程序已不再使用的对象 2、以下叙述正确的是:(B) A.构造方法必须是public方法B.main方法必须是public方法 C.Java应用程序的文件名可以是任意的D.构造方法应该声明为void类型 3、关于Java中数据类型叙述正确的是:(B) A、整型数据在不同平台下长度不同B.boolean类型数据只有2个值,true和false C.数组属于简单数据类型D.Java中的指针类型和C语言的一样 4、设int x=1,float y=2,则表达式x / y的值是:(D) A.0 B.1 C.2 D.以上都不是 5、以下语句有语法错的是:(A) A.int x=1;y=2;z=3 B.for (int x=10,y=0;x>0;x++); C.while (x>5); D.for(; ;); 6、关于类和对象的叙述正确的是:(A) A.Java的类分为两大部分:系统定义的类和用户自定义的类 B.类的静态属性和全局变量的概念完全一样,只是表达形式不同 C.类的成员至少有一个属性和一个方法D.类是对象的实例化 7、以下有关构造方法的说法,正确的是:(A) A.一个类的构造方法可以有多个B.构造方法在类定义时被调用 C.构造方法只能由对象中的其它方法调用 D.构造方法可以和类同名,也可以和类名不同 8、以下有关类的继承的叙述中,正确的是:(D) A.子类能直接继承父类所有的非私有属性,也可通过接口继承父类的私有属性 B.子类只能继承父类的方法,不能继承父类的属性 C.子类只能继承父类的非私有属性,不能继承父类的方法 D.子类不能继承父类的私有属性 9、void 的含义:(C ) A.方法体为空B.定义的方法没有形参 C.定义的方法没有返回值D.方法的返回值不能参加算术运算 10、关于Java中异常的叙述正确的是:(D ) A.异常是程序编写过程中代码的语法错误B.异常是程序编写过程中代码的逻辑错误 C.异常出现后程序的运行马上中止D.异常是可以捕获和处理的

Java期末考试试卷1

信息学院2006—2007学年第二学期期末考试试题A 课程名称:Java 语言程序设计主讲:年级: 班级姓名学号 题号一二三四五合计 分数 一、选择(每题1分,共20分) 1.有一个名为MyClass的public类,想成功编译需满足以下哪个条件?() A. MyClass类中必须定义一个正确的main()方法。 B. MyClass必须定义在MyClass.java源文件中。 C. MyClass类必须定义在MyClass包中。 D. MyClass类必须被导入。 2.以下哪些修饰符不能用于顶层类?( ) A. public B. private C. abstract D. final 3.以下哪个是java中合法的关键字?( ) A. array B. Boolean C. protect D. super 4.以下哪些是合法的标识符?( ) A.%abcd B. 2abcd C. package D. _a_long_name 5.在Java中,一个类可同时定义许多同名的方法,这些方法的形式参数的个数、类型或顺序各不相同。这种面向对象程序的特性称为. () A、隐藏 B、覆盖 C、重载 D、Java不支持此特性 6.有以下代码,请问该程序的运行结果是什么?( ) class Example { public static void main(String args[]){ boolean b=true; System.out.println(b); } } A. 打印输出true B. 打印输出1 C.编译错误 D. 无内容输出 7.以下哪些是基本数据类型?( ) A.int B. String C. Integer D. Float 8. 给出以下代码,请选择正确的选项?( ) class Example{ public static void main(String[] args){ char a=”\u1234”; } } A. 代码编译成功 B. 代码编译成功,但有警告 C. 代码编译失败 9.以下哪个语句用于声明一个二维数组?( ) 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]; 10.给出以下代码,请问该程序的运行结果是什么?()

java试题练习题(第9套)

—— 学年第 学期 《 Java 程序设计 》课程试题 课程号: √ 考试 □ A 卷 √ 闭卷 □ 考查 □ B 卷 □ 开卷 一、单项选择题(20题;每题2分,共40分) 1、下面选项中,___不可以用作变量名的首字符。 A )字母 B )下划线(_) C )数字 D )美元符号(¥) 答案:C (难度系数C )知识点:变量 2、下面语句中,____不会出现编译警告或错误。 A )float f=1.3; B )char c=”a”; C )byte b=25; D )boolean b=null; 答案:C (难度系数B )知识点:赋值相容 3、下列叙述正确的是___。 A )final 类可以有子类 B )abstract 类中只可以有 abstract 方法 C )abstract 类上可以有非abstract 方法,但该方法不可以用final 修饰 D )不可以同时用final 和abstract 修饰一个方法 答案:D (难度系数B ) 知识点:抽象类,抽象方法 4、创建一个标识有“关闭”按钮的语句是___。 A ) TextField b = new TextField(“关闭”); B ) Label b = new Label(“关闭”); C ) Checkbox b = new Checkbox(“关闭”); D ) Button b = new Button(“关闭”); 答案:D (难度系数C ) 知识点:GUI 编程 5、在编写异常处理的Java 程序中,每个catch 语句块都应该与___语句块对应,使得用该语句块来启动Java 的异常处理机制。 班 级 : 姓名: 学号: 试题共 页 加白纸 张 密 封 线

Java期末考试习题库

一、选择题 1、下面关于变量及其作用范围的陈述哪个是不对的?(B ) A.实例变量是类的成员变量。 B.实例变量用关键字static声明。 C.在方法中定义的局部变量在该方法被执行时创建。 D.局部变量在使用前必须被初始化。 2、下面哪条语句把方法声明为抽象的公共方法?(B ) A.public abstract method(); B.public abstract void method(); C.public abstract void method(){} D.public void method() extends abstract; 3、哪个是将一个十六进制值赋值给一个long型变量?(D ) A.long number = 345L; B.long number = 0345; C.long number = 0345L; D.long number = 0x345L; 4、下面的哪个赋值语句是不对的?(A ) A.float f = 11.1; B.double d = 5.3E12; C.double d = 3.14159; D.double d = 3.14D; 5、下面哪个是不合法的标识符?(C ) A.$persons; B.TwoUsers; C.*point; D._endline; 6、若在某一个类定义中定义有如下的方法:final void aFinalFunction( ); 则该方法属于( C )。 A、本地方法 B、静态方法 C、最终方法 D、抽象方法 7、main方法是Java Application程序执行的入口点,关于main方法的方法头以下哪项是合 法的( B )。 A、public static void main() B、public static void main(String[ ] args) C、public static int main(String[ ] args) D、public void main(String arg[ ]) 8、在Java中,一个类可同时定义许多同名的方法,这些方法的形式参数个数、类型或顺序 各不相同,传回的值也可以不相同。这种面向对象程序的特性称为( C )。 A、隐藏 B、覆盖 C、重载 D、Java不支持此特性 9、在Java applet程序中,用户自定义的Applet子类常常覆盖父类的( C )方法来完成 applet界面的初始化工作。

相关文档