Java认证模考试题及答案

合集下载

java考试试题及答案

java考试试题及答案

java考试试题及答案一、选择题1.以下关于Java的说法,哪个是正确的?A. Java是一种编程语言B. Java只能在Windows系统上运行C. Java只用于游戏开发D. Java不能用于Web开发答案:A2.下面哪个关键字用于定义一个类?A. classB. publicC. staticD. void答案:A3.Java中的基本数据类型有哪些?A. int, float, char, booleanB. Integer, Float, Character, BooleanC. String, Double, BooleanD. int, double, String, boolean答案:A4.以下哪个不是Java的访问修饰符?A. publicB. protectedC. privateD. final答案:D5.以下哪种循环结构在未知条件的情况下会被循环执行?A. for循环B. while循环C. do-while循环D. switch语句答案:C二、填空题1.Java中用于接收用户输入的类是__Scanner__。

2.Java中String类的equals()方法用于比较两个字符串的__内容__。

3.在Java中,用于创建对象的关键字是__new__。

4.Java中的集合类是位于__java.util__包下的。

5.Java中的逻辑与运算符是__&&__,逻辑或运算符是__||__。

三、简答题1.请简要介绍Java的特点及优势。

Java是一种跨平台的编程语言,具有以下特点和优势:- 简单易学:Java语法相对简单,与C++相比更容易上手。

- 面向对象:Java支持面向对象编程,具有封装、继承和多态的特性。

- 平台无关性:Java通过虚拟机实现跨平台,只需编写一次代码即可在不同操作系统上运行。

- 安全性:Java有严格的访问控制和内存管理机制,可防止非法访问和内存泄漏。

java试题库及答案

java试题库及答案

java试题库及答案Java试题库及答案一、单选题1. Java语言的特点是什么?A. 面向过程B. 面向对象C. 编译型语言D. 解释型语言答案:B2. 在Java中,用哪个关键字可以定义一个类?A. publicB. classC. voidD. int答案:B3. 下列哪个是Java的合法标识符?A. 2classB. class#2C. _class2D. class:2答案:C4. Java中的main()方法必须定义为什么类型的参数?A. intB. StringC. voidD. None答案:D5. 在Java中,哪个关键字用于实现异常处理?A. tryB. catchC. throwD. All of the above答案:D二、多选题6. 下列哪些是Java的基本数据类型?A. intB. StringC. floatD. boolean答案:A, C, D7. 在Java中,哪些是合法的数组初始化方式?A. int[] arr = new int[10];B. int arr[] = {1, 2, 3};C. int arr = {1, 2, 3};D. int arr = new int[3]{1, 2, 3};答案:A, B8. 下列哪些是Java的控制流语句?A. if-elseB. switch-caseC. forD. try-catch答案:A, B, C三、简答题9. 简述Java的垃圾回收机制。

答案:Java的垃圾回收机制是一种自动内存管理功能,它周期性地执行,回收不再使用的对象所占用的内存空间。

垃圾回收器会跟踪每个对象的引用,当对象的引用计数为0时,即没有任何引用指向该对象,垃圾回收器就会在下一次执行时回收该对象占用的内存。

10. 什么是Java的接口?它有什么作用?答案:Java中的接口是一种完全抽象的类,它不包含任何实现代码,只包含常量和抽象方法的声明。

大学java考试题及答案详解

大学java考试题及答案详解

大学java考试题及答案详解大学Java考试题及答案详解一、选择题1. Java是一种______。

A. 编译型语言B. 解释型语言C. 汇编语言D. 机器语言答案:B2. 下列哪个是Java的关键字?A. ObjectB. StringC. voidD. Array答案:C3. Java中的“==”用于比较什么?A. 引用是否相同B. 引用所指向的对象的值是否相同C. 基本数据类型的值是否相等D. 引用所指向的对象的内存地址是否相同答案:C二、填空题1. Java语言支持的四种访问控制级别是:______、______、______和______。

答案:public, protected, default, private2. Java中,______关键字用于定义一个类可以被继承。

答案:extends三、简答题1. 简述Java的垃圾回收机制。

答案:Java的垃圾回收机制是一种自动内存管理功能,它通过垃圾回收器定期检查不再使用的对象,并释放它们占用的内存。

垃圾回收器不会立即回收对象,而是等到确定对象不再被任何引用指向时才进行回收。

四、编程题1. 编写一个Java程序,实现计算两个整数的和。

```javapublic class SumCalculator {public static void main(String[] args) {int num1 = 10;int num2 = 20;int sum = num1 + num2;System.out.println("The sum is: " + sum);}}```答案:程序定义了一个名为SumCalculator的类,其中包含一个main 方法。

在main方法中,定义了两个整数num1和num2,并计算它们的和,最后通过System.out.println输出结果。

五、论述题1. 论述Java的多线程机制及其应用场景。

java认证考试试题及答案

java认证考试试题及答案

java认证考试试题及答案java认证考试试题及答案1. What gets printed when the following programis compiled and run?class Test {public static void main(String args[]) {int i;do {i++;} while (i < 0);System.out.println(i);}}Select 1 correct answer:A. The program does not compile as i is not initialized.B. The program compiles but does not run.C. The program compiles and runs but does not print anything.D. The program prints 0.E. The program prints 1.答案:A:如果没有初始化便使用基本变量类型,会导致编译时异常,程序不能编译。

2. What gets printed when the following programis compiled and run?public class XYZ {public static void main(String args[]) {int i,j,k;for (i = 0; i < 3; i++){for(j=1; j < 4; j++){for(k=2; k<5; k++){if((i == j) && (j==k))System.out.println(i);} } } } }Select 1 correct answer:A. 0B. 1C. 2D. 3E. 4答案:C3. Given the following code :class Base{}public class MyCast extends Base{static boolean b1=false;static int i = -1;static double d = 10.1;public static void main(String argv[]){MyCast m = new MyCast();Base b = new Base();//Here}}Which of the following, if inserted at the comment //Here will allow the code to compile and run without error? Select 2 correct answers:A. b = m;C. d = i;D. b1 = i;解析:A 从子类型到父类型的转换是扩展引用转换,不需要在运行时采取特殊的动作,不会在运行时抛出异常。

Java试题答案(全)

Java试题答案(全)

一、选择题答案选择第1题B选择第2题A选择第3题C选择第4题B选择第5题A选择第6题A选择第7题B选择第8题C选择第9题B选择第10题B选择第11题C二、多项选择题答案多项选择第1题BD多项选择第2题AE多项选择第3题AC多项选择第4题AE多项选择第5题AE多项选择第6题DEF多项选择第7题AC多项选择第8题BC多项选择第9题AB多项选择第10题CD多项选择第11题CD多项选择第12题ACD多项选择第13题ABD三、填空题答案填空第1题x=10,a=3,b=4,c=5填空第2题java.util填空第3题(public )(static )(void)(main)(String args[])填空第4题1填空第5题26四、编程题答案1public class HelloWorld{public static void main(String args[]) {System.out.println("Hello,World!");}}import java.awt.Graphics;import java.applet.Applet;public class HelloWorld extends Applet{ String s;public void init(){s="Hello World!";}public void paint(Graphics g){g.drawString(s,25,25);}}2class yanghui{public static void main (String args[]) {int i,j;int yhlevel=10;int yanghui[][];System.out.println("杨晖三角形:");yanghui=new int[yhlevel][];for(i=0;i<yanghui.length;i++)yanghui[i]=new int[i+1];yanghui[0][0]=1;for (i=1; i<yanghui.length;i++){yanghui[i][0]=1;for(j=1;j<yanghui[i].length-1;j++)yanghui[i][j]=yanghui[i-1][j-1]+yanghui[i-1][j];yanghui[i][yanghui[i].length-1]=1;}for (i=0; i<yanghui.length;i++){for(j=0;j<yanghui[i].length;j++)System.out.print(yanghui[i][j]+" ");System.out.println();}}}输出结果是:杨晖三角形:11 11 2 11 3 3 11 4 6 4 11 5 10 10 5 11 6 15 20 15 6 11 7 21 35 35 21 7 11 8 28 56 70 56 28 8 11 9 36 84 126 126 84 36 9 13import java.io.*;public class MemoController{FileOutputStream fos;OutputStreamWriter osw;BufferedWriter bw;public MemoController(){try{fos=new FileOutputStream("memo.txt",true);osw=new OutputStreamWriter(fos);bw=new BufferedWriter(osw);}catch(FileNotFoundException e){};}public synchronized void append(String s){try{bw.write(s,0,s.length());bw.flush();bw.close();osw.close();fos.close();}catch(IOException e){}}public static void main(String args[]){MemoController mmc=new MemoController();mmc.append("I am xubin ");}}4import java.io.*;class Phones{static FileOutputStream fos;public static final int lineLength = 81;public static void main(String args[]) throws IOException{byte[] phone = new byte[lineLength];byte[] name = new byte[lineLength];int I;try{fos = new FileOutputStream("phone.numbers");}catch(FileNotFoundException e){ }while (true){System.err.println("Enter a name (enter 'done' to quit)");readLine(name);if ("done".equalsIgnoreCase(new String(name,0,0,4))){break;}System.err.println("Enter the phone number");readLine(phone);for (int i=0;phone[i]!= 0;i++){fos.write(phone[i]);}fos.write(',');for (int i=0;name[i]!= 0;i++){fos.write(name[i]);}fos.write('\n');}fos.close();}private static void readLine(byte line[]) throws IOException {int i=0,b=0;while ((i<lineLength-1)&&((b=System.in.read())!='\n')){line[i++] = (byte)b;}line[i]=(byte) 0;}}。

java面试题库java面试题目及答案(3篇)

java面试题库java面试题目及答案(3篇)

第1篇一、基础知识1. Java简介题目:请简述Java的基本特点。

答案:- 简单易学:Java设计之初就考虑了易学性,使用面向对象编程。

- 原生跨平台:Java通过JVM(Java虚拟机)实现跨平台运行。

- 安全性:Java提供了强大的安全机制,如沙箱安全模型。

- 体系结构中立:Java不依赖于特定的硬件或操作系统。

- 高效:Java的运行速度接近C/C++。

- 多线程:Java内置多线程支持,便于实现并发处理。

- 动态性:Java在运行时可以进行扩展和修改。

2. Java虚拟机题目:请解释Java虚拟机(JVM)的作用。

答案:JVM是Java程序的运行环境,其主要作用包括:- 将Java字节码转换为本地机器码。

- 管理内存,包括堆、栈、方法区等。

- 提供垃圾回收机制。

- 管理线程和同步。

3. Java内存模型题目:请简述Java内存模型的组成。

答案:Java内存模型主要由以下部分组成:- 堆(Heap):存储对象实例和数组。

- 栈(Stack):存储局部变量和方法调用。

- 方法区(Method Area):存储类信息、常量、静态变量等。

- 本地方法栈(Native Method Stack):存储本地方法调用的相关数据。

- 程序计数器(Program Counter Register):存储线程的当前指令地址。

4. Java关键字题目:请列举并解释Java中的几个关键字。

答案:- `public`:表示访问权限为公开。

- `private`:表示访问权限为私有。

- `protected`:表示访问权限为受保护。

- `static`:表示属于类本身,而非对象实例。

- `final`:表示常量或方法不能被修改。

- `synchronized`:表示线程同步。

- `transient`:表示数据在序列化时不会被持久化。

二、面向对象编程5. 类和对象题目:请解释类和对象之间的关系。

答案:类是对象的模板,对象是类的实例。

JAVA模拟试题及答案(一)

JAVA模拟试题及答案(一)

选择看前40,填空看前30第一部分模拟试题第一题单项选择题1、Java语言和c++语言相比,哪一项是Java有的,而c++没有?(D )A、面向对象B、动态链接C、有类库D、跨平台2、下列选项中,不属于Java语言特点的一项是( C )。

A、分布式B、安全性C、编译执行D、面向对象3、在下列选项中,属于Java语言的代码安全检测机制的一项是( B )。

A、动态链接B、访问权限的检查C、通过接口实现多重继承D、将所有的Java应用都看做对象,按类进行封装4、下列选项中,不属于Java语言安全机制的一项足( D )。

A、语法检查B、不允许使用指针C、代码参数类型合法性检查D、对内存进行跟踪5、下面关于Java代码安全的说法哪一项是不正确的( B )?A、Java程序在解释执行时所需要的类都是通过字节码校验程序装入的B、Java字节码的执行是由JVM中的编译器完成的C、在Java程序运行时,首先装入字节码,然后进行校验,最后在解释器中执行D、在默认的安全配置条件下,Applet不能访问任何本地资源6、下列API不属于java .1ang.Math类的一个是(C )。

A、random() (随机数)B、abs()C、drawLine()D、sin()7、阅读下列代码段,选出该代码段的正确的文件名( D )。

class A{void methodl(){System.out.println(”methodl in class A”):}}public class Bvoid method2(){System.out.println(”method2 in class B”):}public static void main(String args[]){System.out.println(”main()in class B”):}}A、A .javaB、A.classC、B.classD、B.java8、编译下面源程序会得到哪些文件?(C )class AI{}elass A2{}Public class B{Public static void main(String args[ ]){}}A、只有B.class文件B、只有A1.Class和A2.class文件C、有A1.class、A2.Class和B.class文件D、编泽不成功9、定义类头时能使用的修饰符是( D )。

java考试题及答案

java考试题及答案

java考试题及答案一、单选题1. 在Java中,以下哪个关键字用于定义一个类?a) classb) newc) publicd) void答案:a) class2. 下列选项中,哪个是Java的基本数据类型?a) Stringb) Integerc) Booleand) Object答案:c) Boolean3. 下面哪个关键字用于创建一个新的实例对象?a) staticb) finalc) instance答案:d) new4. Java中的继承是指什么?a) 一个类实现另一个类的属性和方法b) 一个类派生出另一个类,新类拥有原来类的属性和方法c) 一个类使用另一个类的属性和方法d) 一个类包含另一个类的属性和方法答案:b) 一个类派生出另一个类,新类拥有原来类的属性和方法5. 在Java中,以下哪个关键字用于声明一个变量不可修改?a) constantb) finalc) staticd) abstract答案:b) final二、多选题1. 以下哪些操作符可以用于控制流程?a) ifb) ford) switch答案:a) ifb) forc) whiled) switch2. Java中的异常处理机制包括以下哪些部分?a) tryb) catchc) throwd) finally答案:a) tryb) catchd) finally三、简答题1. 请简要解释Java中的多态性是什么意思。

答案:Java中的多态性是指同一个接口,能够有多个不同的实现类。

通过多态性,可以实现方法的动态绑定,在运行时根据具体的对象类型调用相应的方法。

这样可以提高代码的灵活性和可扩展性。

2. 请解释Java中的访问修饰符public、protected、private和default之间的区别。

答案:public修饰的成员变量或方法可以在任何地方被访问;protected修饰的成员变量或方法可以被子类和同一个包内的类访问;private修饰的成员变量或方法只能在当前类中被访问;default修饰的成员变量或方法可以在同一个包内被访问。

java考试题及答案

java考试题及答案

java考试题及答案一、选择题(每题2分,共20分)1. 在Java中,以下哪个关键字用于定义一个类?A. classB. interfaceC. enumD. struct答案:A2. Java中的main方法的返回类型是什么?A. voidB. intC. StringD. boolean答案:B3. 下列哪个是Java的原始数据类型?A. StringB. intC. ArrayListD. Object答案:B4. 在Java中,哪个关键字用于实现多态?A. newC. implementsD. override答案:D5. 以下哪个是Java集合框架中的接口?A. ListB. SetC. MapD. All of the above答案:D6. Java中的异常处理是通过哪两个关键字实现的?A. try and catchB. if and elseC. for and whileD. switch and case答案:A7. 以下哪个是Java的访问修饰符?A. publicB. staticC. finalD. synchronized答案:A8. 在Java中,哪个关键字用于定义一个接口?B. interfaceC. packageD. enum答案:B9. Java中的String类是不可变的,这意味着什么?A. 字符串值不能被修改B. 字符串对象不能被实例化C. 字符串不能被用作数组D. 字符串不能被用作方法参数答案:A10. 在Java中,哪个关键字用于定义一个枚举类型?A. enumB. classC. interfaceD. struct答案:A二、简答题(每题5分,共20分)1. 简述Java中的垃圾回收机制。

答案:Java中的垃圾回收机制是一种自动内存管理功能,它会自动检测不再使用的对象,并释放它们占用的内存。

垃圾回收器会周期性地运行,寻找那些没有被任何引用指向的对象,然后回收它们占用的内存空间。

JAVA模拟考试(答案)

JAVA模拟考试(答案)

JAVA模拟考试(答案)Java模拟考试一、名词解释1、java的三个基本特征,并加以解释2、从用户的角度看,Java源程序中的类分为哪两种3 解释this,super的使用场合4、在java语言说明类的成员有哪四种级别的访问控制5、说明重载与覆盖的区别6、在java语言中写出定义类的最一般形式7、类修饰符用于指定类的使用特性和访问权限,通常有哪几种8、简单说明静态成员变量的特征二、选择题1、下面程序段的输出结果是:int a = 3;a++);a);A.444 B.445 C. 345 D.344结果:2、以下哪些是基本数据类型B. StringC. integerD. Float结果:3、选择以下程序运行结果" " +4 + 5;+ 5);+ 5 +"");+ "" +5);A.第3行出现编译错误 B.输出45, 7, 7 和45.C.输出7, 7, 7 和45. D.输出 45, 7, 45 和45.结果:4、选择以下程序运行结果public class test {public static void main(String args[]) {int x=2,y=2,z=2;if (x-- == 1 && y++ == 1 || z++ == 1)"x=" + x + ",y=" + y + ",z=" + z);} }A. x=1,y=3,z=2 B. x=2,y=3,z=2C. x=1,y=2,z=2 D. x=1,y=3,z=3结果:5、编译和运行以下代码结果为:public class EqualsTest{public static void main(String args[]){byte A=(byte)4096;if(A==4096) "Equal");else "Not Equal");} }A.在第3行出现转换丢失精度的编译错误. B.输出 "Not Equal".C.输出“Equal“. D. 无输出结果结果:6、现有一个int类型的整数和一个double类型的数进行加法运算,则得到的结果类型为()A.int类型 B. double类型 C. float类型 D. long类型7、以下程序的运行结果为()public class Test{public static void main(String argv[ ]){"x="+5); } }A. 5B. x=5C. "x="+5D. "x="58、以下程序的运行结果为()public class Test{public static void main(String argv[ ]){ "good"+"morning"); } }A. goodmorningB. "good"+"morning"C. good morningD. good+morning9、选择以下程序运行结果()以下代码的输出结果public class Test{int x=3;public static void main(String argv[]){int x= 012;}}A.12 B.012 C.10 D.3 10、选择以下程序运行结果()public class Exa{public static void main(String[] args){ int var1=10;int var2=20;+ " " + var2);}}A. 3021 21 C. 1020 21 2011、请问,以下代码片段错在何处()switch(i==10)case 1:++i;break;case 2:--i;case 3:i*=5;break;default:i%=3;}A. switch表达式的结果必须是一个整数类型B.第一个case的选择因子值是一个字符型C.第二个case的选择因子值是一个字符串型D.第二个case的选择分支中缺少break语句三、写出下列程序的运行结果1、class Variable{int x=1,y=2,z=3;void init( int x, int y ){= x;=y;int z=5;"**** in init ****");"x = “+x+" y = “+y+" z = "+z);} }public class test1 {public static void main( String[] args) { Variable birth = new Variable();(10,20);} 结果:**** in init ****X = 10 y = 20 z = 52、public class SimpleDataType {public static void main (String args [ ] ) { int i = 3; byte bi = (byte)i;short si = 20000;int li=(int);float f = 3.14f;"\t"+si+"\t"+i+"\t"+li+"\t"+f);boolean b = false;int i1 = 4;b = ( i1!= 0 );"\n"+b);} }结果:3 20000 3 4true3、 class A{void callme(){"Inside A's callme() method");}}class B extends A{void callme(){"Inside B's callme() method");}}public class Chinese{public static void main(String [] args){B a=new B();}} 结果:Inside B's callme() method4、public class test {public static void main(String a[]) { "\t");"\t");"\t");"\t");"%="+%;}} 结果:1 1 -1 -1%=5、public class A {protected void test(int x,int y) { "test(int,int):"+x+" "+y); } protected void test(int x){ "test(int):" + x); }protected void test(String str ){ "test(String):" + str); }public static void main (String[] args){ A a1 = new A();("hello");(5,4); }} }结果:test(String):hellotest(int,int):5 46、 public class test {public static void main(String a[]) {int m=0;"m++="+m++);"++m="+(++m));boolean x;x=(5>3)&&(4==6);"x="+x);m=m%2;"result="+m+1);int y=m*m+2*m-1;"m="+m+",y="+y);}}结果:m++=0++m=2x=falseresult=01m=0,y=-16、class Point {int x,y;public Point(int x1,int y1) {x=x1;y=y1;}public static void main(String args[]) { Point p1=new Point(2,3);Point p2=new Point(3,5);Point p3=p1;=18;p1=p2;}}【运行结果】1837、public class Test{int i=1;public static void main(String[] args){ Test x= new Test();(3); }void thisDemo(int i){= i;} }【运行结果】3138、class Father{private String str=“父类实例变量”; static{父类静态方法”);} public Father(){父类构造方法”);}{ }}class Son extends Father{private String str=“子类实例变量”; { }static{子类静态方法”);}Son(){子类构造方法”);}public static void main(String[] arge){ new Son(); }}【运行结果】父类静态方法子类静态方法父类实例变量父类构造方法子类实例变量子类构造方法9、class parent {int a=3;void f(){a=a+1;} }public class Chinese extends parent {int a=6;Chinese(){();a= a+ -2;"a="+a);}public static void main(String[] args) { Chinese cn=new Chinese(); } }【运行结果】a=810、Class jj { protected int x = 0;protected void test(int x) {"test(int):" + x); }protected void test(String str ) {"test(String):" + str); }protected void test(float x) {"test(float):" + x );}protected void test(Object obj) {"test(Object):" + obj );}public static void main (String[] args) { jj a1 = new jj();("hello"); (5);;} }【运行结果】test(String): hellotest(int):5test(float):四、编写程序1 求任意一元二次方程的解,若无实数解,求出虚数解。

JAVA模考试卷参考答案

JAVA模考试卷参考答案

1.一个Java程序运行从上到下的环境次序是( )A、操作系统、Java程序、JRE/JVM、硬件。

B、JRE/JVM、Java程序、硬件、操作系统C、Java程序、JRE/JVM、操作系统、硬件。

D、Java程序、操作系统、JRE/JVM、硬件2.下面代码的运行输出结果是(A )public class Test {public static void main(String args[]) {int x = 0;if (x > 0)x = 1;switch (x) {case 1:System.out.println(1);case 0:System.out.println(0);case 2:System.out.println(2);break;case 3:System.out.println(3);default:System.out.println(4);break;}}}(A) 02(B) 43(C) 23(D) 13. (1.5分) 下列选项中的哪个关键字通常用来对对象进行加锁,该标记使得对对象的访问是排他的。

(A) transient (B) synchronized (C) serialize (D) static4. (1.5分) 下列关于变量及其范围的陈述中不正确的是(A) 实例变量是类的成员变量。

(B) 实例变量用关键字static声明。

(C) 在方法中定义的局部变量在该方法被执行时创建。

(D) 局部变量在使用前必须被初始化。

5. (1.5分) 下列程序片断可能发生错误的是(A) String s= "Welcome to our school";String t= "thanks";String k=s+t;(B) String s= "Welcome to our school";String standard=s.toUpperCase();(C) String s= "Welcome to our school";String t;t=s[3]+ "again";(D) String s= "Welcome to our school";String t= s+"school";6. (1.5分) 在一个Java源文件中定义了3个类和15个方法,编译该Java源文件时会产生个字节码文件,其扩展名是。

java考试题及答案

java考试题及答案

java考试题及答案一、选择题1. Java中用于创建新对象的关键字是()。

A. classB. newC. thisD. super答案:B2. 下列哪个选项是Java语言的特点?()A. 支持多继承B. 所有代码必须位于类中C. 支持自动垃圾回收D. 所有选项都是答案:C3. 在Java中,如果需要实现多线程,应该继承哪个类?()A. ObjectB. ThreadC. RunnableD. System答案:B4. 下列关于Java异常处理的描述,哪项是错误的?()A. try块可以单独使用B. catch块必须跟随在try块之后C. finally块用于执行清理操作,无论是否发生异常都会执行D. throw关键字用于手动抛出异常答案:A5. 在Java中,下列哪个是正确的数组初始化方式?()A. int[] arr = {1, 2, 3} {4, 5, 6};B. int[] arr = new int[3];C. int[] arr = new int[] {1, 2, 3};D. int[] arr = {1, 2, 3, 4, 5};答案:C二、填空题1. 在Java中,每一个类都是从______类隐式继承而来的,因此所有的类都具有该类的属性和方法。

答案:Object2. Java中的______关键字用于定义一个类为另一个类的子类,实现代码的复用。

答案:extends3. 当需要在Java程序中捕获多种类型的异常时,可以使用______关键字来指定多个捕获类型。

答案:catch4. 在Java中,______关键字用于定义一个方法或构造器的参数类型和顺序。

答案:paramter5. 如果需要在Java中定义一个接口,应该使用______关键字。

答案:interface三、判断题1. Java中的所有异常都是ng包的Throwable类的子类或孙子类。

()答案:正确2. 在Java中,所有的类都必须显式地指定一个父类。

java考试题及答案

java考试题及答案

java考试题及答案题一:什么是Java语言的特点?请简要描述。

答:Java语言具有简单、面向对象、分布式、可移植、高性能、多线程和动态等特点。

它的简单性体现在语法简洁清晰,易于学习和使用。

面向对象的特点使程序更易于维护和扩展。

分布式特性使Java程序可以在不同的机器上运行,实现远程调用。

可移植性使Java程序可以在不同平台上运行,无需修改。

高性能使其成为一种快速响应的开发语言。

多线程和动态特性使Java程序更具并发性和灵活性。

题二:Java语言有哪些数据类型?请列举并简要描述每种数据类型。

答:Java语言包括基本数据类型和引用数据类型。

基本数据类型包括整数类型(byte、short、int、long)、浮点类型(float、double)、字符类型(char)和布尔类型(boolean)。

引用数据类型包括类、接口、数组等。

基本数据类型在内存中直接存储数据的值,而引用数据类型存储的是对象的引用地址。

题三:Java中如何创建对象?请简要描述对象的创建过程。

答:在Java中,通过使用关键字“new”来创建对象。

对象的创建过程包括分配内存、初始化对象属性和调用构造方法。

“new”关键字首先在内存中分配空间来存储对象,然后初始化对象的实例变量,最后调用构造方法对对象进行初始化。

题四:Java中的继承是如何实现的?请简要描述继承的概念及实现方法。

答:继承是面向对象编程中的重要概念,它允许子类从父类继承属性和方法。

在Java中,通过使用关键字“extends”来实现类的继承。

子类继承父类的属性和方法,可以重写方法以实现特定的功能。

继承可以实现代码的复用和提高代码的可维护性。

题五:Java中的多态是如何实现的?请简要描述多态的概念及实现方法。

答:多态是面向对象编程中的重要概念,它允许不同的子类对象通过父类的引用来调用同一个方法,实现了方法的重载和覆盖。

在Java 中,多态通过方法重写和接口实现来实现。

子类重写父类的方法,可以根据对象的实际类型来调用相应的方法。

java试题库及答案

java试题库及答案

java试题库及答案1. 以下哪个选项不是Java的基本数据类型?A. intB. doubleC. StringD. float答案:C2. Java中的`==`和`equals()`方法有什么区别?A. `==`用于比较对象的引用,`equals()`用于比较对象的值B. `==`用于比较对象的值,`equals()`用于比较对象的引用C. 两者都用于比较对象的值D. 两者都用于比较对象的引用答案:A3. 在Java中,下列哪个关键字用于定义一个接口?A. classB. interfaceC. abstractD. final答案:B4. 下列哪个选项是Java中的多态?A. 一个方法可以有多个实现B. 一个方法可以有多个重载C. 一个类可以继承多个类D. 一个类可以有多个接口答案:A5. Java中,下列哪个选项不是访问修饰符?A. publicB. privateC. protectedD. static答案:D6. 在Java中,下列哪个关键字用于抛出异常?A. tryB. catchC. throwD. finally答案:C7. 下列哪个选项是Java中的集合框架?A. CollectionsB. ArraysC. StreamsD. All of the above答案:D8. 在Java中,下列哪个选项用于创建线程?A. implements RunnableB. extends ThreadC. implements CallableD. Both A and B答案:D9. Java中的垃圾回收机制是做什么的?A. 编译代码B. 运行代码C. 自动回收不再使用的对象D. 管理内存分配答案:C10. 下列哪个选项不是Java中的异常类型?A. RuntimeExceptionB. IOExceptionC. SQLExceptionD. Exception答案:D。

java考试题及答案

java考试题及答案

java考试题及答案一、选择题1. Java中用于创建新对象的关键字是()。

A. newB. classC. thisD. super答案:A2. 下列哪个选项是Java的非访问修饰符?()。

A. publicB. privateC. protectedD. static答案:D3. 在Java中,如果一个类没有显式地指定继承关系,则它默认继承()类。

A. ObjectB. SystemC. StringD. null答案:A4. 下列关于Java异常处理的描述,正确的是()。

A. try块中必须跟catch块B. catch块中可以再次抛出异常C. finally块可以在任何时候执行D. throw关键字用于定义异常答案:B5. 在Java中,哪个接口表示允许对象成为“foreach”语句的目标?()。

A. IterableB. CollectionC. ExecutorD. Observable答案:A二、填空题1. 在Java中,使用________关键字可以定义一个包。

答案:package2. 如果需要导入Java标准库中的所有类,可以使用________关键字。

答案:import3. 在Java中,所有的类都是从________类直接或间接派生出来的。

答案:Object4. 为了捕获多种类型的异常,可以使用________关键字。

答案:|(在中文环境下表示为“或”)5. 为了在Java中创建一个线程,需要让类实现________接口或继承________类。

答案:Runnable, Thread三、判断题1. Java中的每条语句都以分号结束。

()答案:正确2. 在Java中,所有的数组都是从Object类继承的。

()答案:正确3. 一个Java类可以有多个public构造方法。

()答案:正确4. 所有的Java异常都是ng.Throwable类的子类。

()答案:正确5. 接口中的方法默认是public和abstract的。

java考试题及答案

java考试题及答案

java考试题及答案一、选择题(每题2分,共20分)1. Java语言的标识符可以包含以下哪些字符?A. 数字B. 下划线C. 美元符号D. 空格答案:B2. 下列哪个选项是Java中的关键字?A. classB. mainC. publicD. all of the above答案:D3. Java中,哪个修饰符表示成员变量或方法是私有的?A. publicB. privateC. protectedD. static答案:B4. Java中,哪个关键字用于捕获异常?A. tryB. catchC. finallyD. throw答案:B5. 在Java中,下列哪个数据类型是基本数据类型?A. StringB. intC. ArrayListD. HashMap答案:B6. 下列哪个选项不是Java集合框架的一部分?A. ListB. MapC. SetD. String答案:D7. Java中,哪个关键字用于定义接口?A. classB. interfaceC. abstractD. final答案:B8. 在Java中,下列哪个选项不是线程安全的?A. VectorB. ArrayListC. LinkedListD. HashMap答案:B9. Java中,下列哪个选项是正确的继承关系?A. Object is a subclass of StringB. String is a subclass of ObjectC. Object is a superclass of StringD. String is a superclass of Object答案:B10. 下列哪个选项不是Java中的访问修饰符?A. publicB. privateC. protectedD. global答案:D二、填空题(每题2分,共20分)1. Java中,用于定义类的关键字是______。

答案:class2. Java中,用于定义接口的关键字是______。

java考试题及答案

java考试题及答案

java考试题及答案Java考试题及答案一、选择题(每题2分,共20分)1. Java语言属于以下哪类编程语言?A. 过程式编程语言B. 面向对象编程语言C. 函数式编程语言D. 逻辑编程语言答案:B2. Java程序的执行入口是以下哪个方法?A. main()B. init()C. start()D. run()答案:A3. 下列哪个关键字用于定义类?A. classB. interfaceC. enumD. struct答案:A4. Java中,哪个关键字用于定义一个方法?A. methodB. functionC. procedureD. void答案:D5. 在Java中,哪个关键字用于实现继承?A. extendsB. inheritC. derivedD. subclass答案:A6. 下列哪个是Java中的访问修饰符?A. publicB. privateC. protectedD. All of the above答案:D7. Java中,哪个关键字用于抛出异常?A. tryB. catchC. throwD. finally答案:C8. Java中,哪个类是所有Java类的父类?A. ObjectB. ClassC. SystemD. Thread答案:A9. 在Java中,哪个关键字用于定义接口?A. classB. interfaceC. abstractD. package答案:B10. 下列哪个是Java集合框架中的接口?A. ListB. SetC. MapD. All of the above答案:D二、简答题(每题10分,共30分)1. 简述Java的垃圾回收机制。

答案:Java的垃圾回收机制是一种自动内存管理功能,它通过垃圾回收器定期检查不再被引用的对象,并释放它们占用的内存。

垃圾回收器运行在后台,开发者不需要手动释放对象内存。

2. 描述Java中多态的概念及其实现方式。

java考试试题及答案

java考试试题及答案

java考试试题及答案一、选择题(每题2分,共20分)1. 下列哪个是Java的基本数据类型?A. StringB. IntegerC. intD. Object答案:C2. Java中的main方法是程序的入口点,它属于哪个类?A. ng.ObjectB. ng.SystemC. ng.RuntimeD. java.applet.Applet答案:A3. 下列哪个关键字用于定义类?A. classB. publicC. staticD. void答案:A4. Java中的哪个关键字用于实现接口?A. implementsB. extendsC. classD. interface答案:A5. 下列哪个是Java集合框架中的接口?A. ArrayListB. ListC. LinkedListD. HashMap答案:B6. 下列哪个不是Java的控制流语句?A. ifB. forC. switchD. while答案:C7. Java中的哪个类提供了日期和时间的处理功能?A. java.util.DateB. java.util.CalendarC. java.time.LocalDateD. java.time.LocalDateTime答案:B8. 下列哪个是Java的异常处理关键字?A. tryB. catchC. finallyD. all of the above答案:D9. 下列哪个不是Java的访问修饰符?A. publicB. privateC. protectedD. global答案:D10. 下列哪个不是Java的注释方式?A. // 单行注释B. /* 多行注释 */C. / 文档注释 */D. # 预处理指令答案:D二、填空题(每空2分,共20分)1. Java语言是________面向对象的编程语言。

答案:完全2. Java程序的执行流程是:编写源代码,编译成字节码,通过________加载并执行。

java初级试题及答案

java初级试题及答案

java初级试题及答案一、选择题(每题2分,共10分)1. Java语言的创始人是:A. James GoslingB. Dennis RitchieC. Bjarne StroustrupD. Guido van Rossum答案:A2. 下列哪个选项不是Java语言的特性?A. 平台无关性B. 面向对象C. 编译型语言D. 多线程答案:C3. Java中,用于捕获异常的关键字是:A. tryB. catchC. throwD. finally答案:B4. 下列哪个关键字用于定义接口?A. classB. interfaceC. abstractD. final答案:B5. Java中,用于创建线程的构造方法是:A. run()B. start()C. main()D. execute()答案:B二、填空题(每题2分,共10分)1. Java程序的执行入口是________方法。

答案:main2. Java中,________关键字用于声明一个类。

答案:class3. 在Java中,________关键字用于实现多态。

答案:extends4. Java中,________关键字用于实现接口。

答案:implements5. Java中,________关键字用于声明一个方法。

答案:void三、简答题(每题5分,共20分)1. 请简述Java平台的三个主要组成部分。

答案:Java平台的三个主要组成部分是Java虚拟机(JVM)、Java API和Java语言。

2. 解释Java中的垃圾回收机制。

答案:Java中的垃圾回收机制是指自动回收不再被使用的对象所占用的内存,以避免内存泄漏。

3. 描述Java中集合框架的主要接口。

答案:Java中集合框架的主要接口包括List、Set和Map。

4. 请解释Java中的异常处理机制。

答案:Java中的异常处理机制包括try、catch、finally和throw 关键字,用于捕获和处理程序运行过程中出现的异常。

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

Java认证模考试题及答案Question: 1Given 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 mB. change private int m to public int mC. change private int m to static int mD. change private int m to int mExplanation: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 60Question: 2Which 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 60Question: 3中国公务2004-5-27 22:14:08Given the following fragment of code:public class Base{public Base(int a,int b){x=a; y=b;}public Base(int a, int b, int c, int d){// assignment x=a, y=bw=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 60Question: 4Given 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 60Question: 5What is the return value of the main() method in Java?A. StringB. intC. charD. voidExplanation:The main() method in Java returns void.Correct Answer: D 5 of 60Question: 6Which are the valid identifiers in Java?A. fieldnameB. superC. 3numberD. #numberE. $numberExplanation: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 60Question: 7Which are valid Java keywords?A. constB. NULLC. falseD. thisE. nativeExplanation: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 60Question: 8 2005-8-16 3:14:42Which are valid integral expressions in Java?A. 22B. 0x22C. 022D. 22HExplanation:In Java integral has three forms: decimal, octal and hexadecimal. Octal values start with a zero and hexadecimal values start withCorrect Answer: A,B,C 8 of 60Question: 9Which one of the following ranges of short is correct?Explanation:The length of the short data is 16 bits. The range of short isThe length of the short data is 16 bits. The range of short isCorrect Answer: D 9 of 60Question: 10Which one of the following ranges of byte is correct?Correct Answer: B 10 of 60Question: 11 2004-5-27 22:14:08Given the following fragment of code, what are results of i and j after execution?int i = 1;int j;j = i++;A. 1, 1B. 1, 2C. 2, 1D. 2, 2Explanation: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 60Question: 12Which of the following statements are true?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 60Question: 13Which of the following assignments are legal?A. float a = 2.0B. double b = 2.0C. int c = 2D. long d = 2Explanation: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 60Question: 14Which one of the following arguments is the correct argument of the main() method?A. char args[]B. char args[][]C. String arg[]D. String argsExplanation: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 60Question: 15Which 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] isCorrect Answer: A,B,D,E 15 of 60Question: 16Given 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.lengthC. m.length()+1D. m.length+1Explanation:The number of elements in an array is stored in the length attribute in the array object.Correct Answer: B 16 of 60Question: 17Given the following command to run a correct class: java MyTest a b cWhich statements are true?A. args[0] = MyTest a b cB. args[0] = MyTestC. args[0] = aD. 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 60Question: 18Given 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 60Given the following fragment of code:boolean m = true;if ( m = false )System.out.println(False);elseSystem.out.println(True);What is the result of the execution?A. FalseB. TrueC. NoneD. 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 60Question: 20Given 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. 5B. 4C. 6D. FinishedE. NoneExplanation: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 60Question: 21What 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 0B. 0 and 1C. 0 and 2D. 1 and 0E. 1 and 1F. 1 and 2G. 2 and 0H. 2 and 1I. 2 and 2Explanation: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 60Question: 22Given 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. 0B. 1C. 2D. 3E. 4F. NoneExplanation:In the block of switch, if there is no break sentence in one case the following sentences will be executed.Correct Answer: A,B,C 22 of 60Question: 23Which method is called when the browser returns to the page containing the applet after moving to another URL?B. start()C. stop()D. destroy()Explanation:The start() runs whenever the applet becomes visible, such as when the browser returns to the page containing the applet after moving to another URL or the browser is restored after being iconized.Correct Answer: B 23 of 60Question: 24If a thread calls the wait() method, which methods can make it continue to run?A. join()B. resume()C. notify()D. notifyAll()E. high priority thread is readyExplanation:If a thread issues a wait() call it will pause execution until another thread issues a notify() or notifyAll() call. The pair of the methods are provided for thread communication.Correct Answer: C,D 24 of 60Question: 25Which method is used to define the execution body of a thread?A. start()B. init()C. run()D. main()E. synchronized()Explanation:The threads will always begin executing at the run() method, which contains the definition of the execution body.Correct Answer: C 25 of 60Question: 26Which keyword is used to allow interaction with the lock flag?A. nativeB. staticC. synchronizedD. abstractExplanation:Every object has a lock flag. The synchronized keyword enables interaction with the flag, which allow exclusive access to thatCorrect Answer: C 26 of 60Question: 27Which modifiers are legal in Java?A. privateB. publicC. protectedD. protectE. friendExplanation:The public, private, protected and no modifier are legal modifiers. The friend and protect are illegal in Java.Correct Answer: A,B,C 27 of 60Question: 28If a member variable of a class can be accessible only by the same package, which modifier should be used?A. privateB. publicC. protectedD. no modifierE. finalExplanation:No modifier is the default access level. The default modifier means to be accessible by the classes in the same package. Correct Answer: D 28 of 60Question: 29Which modifier should be used to define a constant member variable?A. staticB. finalC. abstractD. No modifier can be usedExplanation:If a member variable is marked as final, it is a constant.Correct Answer: B 29 of 60Question: 30Which one of the following is correct to declare a native method?A. public native void test();B. public native void test(){}C. public void native test();Explanation:A native method can not have a method body. And the keyword native can't be put in front of the return value of the method. Correct Answer: A 30 of 60Question: 31Given the following definition of a class: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...}}Which of the following usage are legal?A. t.fB. this.nC. Test.mD. Test.nExplanation:The f and m are instance variables. They should be accessed through an object. The n is a class variable and it should be accessed through the class name.Correct Answer: A,D 31 of 60Question: 32Given the following code: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) }Which line will cause an error?A. line 3B. line 6C. line 10D. line 14E. line 15Explanation:The Demo class doesn't have a constructor that takes one String argument. The call on line 15 will cause an error.Correct Answer: E 32 of 60Question: 33Given the following class definition in one source file:class Base {public Base (){ //... }public Base ( int m ){ //... }protected void fun( int n ){ //... }}public class Child extends Base{// member methods}Which methods can be added into the Child class correctly?A. private void fun( int n ){ //...}B. void fun ( int n ){ //... }C. protected void fun ( int n ) { //... }D. public void fun ( int n ) { //... }E. public m(){ //... }Explanation:In the subclass Child the overriding methods cannot be less accessible than the method they overrides in the super class Base. Correct Answer: C,D 33 of 60Question: 34Which statements are correct?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.Explanation:A subclass inherits all methods except the constructor from the superclass. When a class implements an interface, it can define all the methods of the interface.Correct Answer: A,C 34 of 60Question: 35In the Test.java source file, which are correct class definitions?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;}}Explanation:In the Test.java source file the class name should be Test, not test, for it is case-sensitive in Java. One class should have not more than one superclass. The protected modifier can not be put in front of the class.Correct Answer: B,D 35 of 60Question: 36The Person, Student and Teacher are class names. These classes have the following inheritance relation as shown below:Person---------------| |Student TeacherThere is the following expression in a Java source file:Person p = new Student();Which one of the following statements are true?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.Explanation:The objects cast up the class hierarchy are always permitted. A reference of superclass can refer to an object of subclass.Correct Answer: A 36 of 60Question: 37The Person, Student and Teacher are class names. These classes have the following inheritance relation as shown below:Person|---------------| |Student TeacherIn Java source file a specific method has an argument. In order to handle all these classes in this method which type of argument of this method should be used?A. PersonB. StudentC. TeacherD. ObjectE. None of them can be used.Explanation:The objects of subclasses can pass around using references to their parent classes. The Person and Object are superclasses of the Teacher and Student classes. The type of the argument of the method should be Person or Object.Correct Answer: A,D 37 of 60Question: 38The Person, Student and Teacher are class names. These classes have the following inheritance relation as shown below:Person|---------------| |Student TeacherPerson p = new Teacher();Which of the following expressions return true?A. p instanceof TeacherB. p instanceof StudentC. p instanceof PersonD. None of them returns trueExplanation:The instanceof operator is used to test the type of an object. Because the reference p refers to a Teacher object and the Teacher is a subclass of the Person class the expressions in answer A and C will return true.Correct Answer: A,C 38 of 60Question: 39Given the following code:public class Test{public static void main(String args[]){String str=new String(World);char ch[]={'H','e','l','l','o'};change(str,ch);System.out.println(str + and + ch);}public static void change(String str, char ch[]){str=Changed; ch[0]='C';}}What is the result after execution?A. World and HelloB. World and CelloC. Changed and HelloD. Changed and CelloExplanation:Java passes arguments only by value. When an object instance is passed as an argument to a method, the value of the argument is a reference to the object. The contents of the object can be changed in the called method, but the object reference is never changed.Correct Answer: B 39 of 60Question: 40Given the following fragment of code:Double d1 = new Double(1.0);Double d2 = new Double(1.0);Float f = new Float(1.0F);A. d1 == d2B. d1.equals(d2)C. d1 = fD. f.equals(d1)Explanation:The == operator determine if reference values refer to the dame object. The equals() method is overridden in the Double, Float, String etc. class to compare the content of the objects.Correct Answer: B 40 of 60Question: 41Given the following code:public void fun (){int i;try{i=System.in.read ();System.out.println(Location 1);} catch (IOException e) {System.out.println(Location 2);} finally {System.out.println(Location 3);}System.out.println(Location 4);}If an IOException occurs, what will be printed?A. Location 1B. Location 2C. Location 3D. Location 4Explanation:When an IOException occurs the Location 1 is skipped. Fist the exception is caught and the Location 2 is printed. Then the Location 3 in the block of finally is printed. Finally, the Location 4 is printed.Correct Answer: B,C,D 41 of 60Question: 42If the method func() is allowed to throw out the IOException, which declaration of this method can used?A. public int func(int i)B. public int func(int i) throw IOExceptionC. public int func(int i) throw ExceptionD. public int func(int i) throws IOExceptionE. public int func(int i) throws ExceptionExplanation:The throws keyword should be used when declaration of a method. In the declaration IOException and its superclass Exception can be used.Correct Answer: D,E 42 of 60Question: 43Given the following expression:String f = null;Which of the following expressions will throw an exception?A. f == null | f.length()>10B. f != null | f.length()>10C. f == null || f.length()>10D. f != null || f.length()>10Explanation:The operator || perform short-circuit logical expressions. If the first subexpression is true the second subexpression is skipped, for the entire expression is true when the first subexpression is true. The operator | doesn't perform short-circuit logical expressions. Both of the two subexpressions are performed. Because the f is null the expression f.length() will cause an exception is thrown. Correct Answer: A,B,D 43 of 60Question: 44Which of the following can be parts of the Java source file Calculation1.java?A. public class Calculation1{//...}B. import java.io.*;C. package myPackage;D. import java.awt.*;E. static class Arg{//...}F. class Calcu{//...}G. public class Calculation2{//...}Explanation:The static can not be a modifier before the keyword class. A Java source file can have only one public class.Correct Answer: A,B,C,D,F 44 of 60Question: 45Which one of the following containers must be added to another container?A. WindowB. FrameC. DialogD. PanelExplanation:The Window, Frame and Dialog are free-standing windows. But the Panel is contained within another container, or inside a Web browser's window.Correct Answer: D 45 of 60Question: 46Which of the following classes are layout managers in Java?A. CardLayoutB. BorderLayoutC. PanelLayoutD. GridLayoutE. BagLayoutExplanation:There are five layout managers in Java. They are FlowLayout, BorderLayout, CardLayout, GridLayout and GridBaglayout. Correct Answer: A,B,D 46 of 60Question: 47A Button is positioned in a Frame. Only height of the Button is affected by the Frame while the width is not. Which layout manager should be used?A. FlowLayoutB. CardLayoutC. North and South of BorderLayoutD. East and West of BorderLayoutE. GridLayoutExplanation:In the East and West of BorderLayout only the height of the component is affected when the Frame is resized.Correct Answer: D 47 of 60Question: 48A Button is positioned in a Frame. Its size is not affected when the Frame is resized. Which layout manager should be used?A. FlowLayoutB. CardLayoutC. North and South of BorderLayoutD. East and West of BorderLayoutE. GridLayoutExplanation:The size of the components is not constrained by the FlowLayout manager. When the area is resized the size of these components is not changed.Correct Answer: A 48 of 60Question: 49Which methods can get the event source in the WindowEvent?A. getFrame()B. getID()C. getSource()D. getWindow()Explanation:The methods getSource() and getWindow() can be used to get the event sources of the window events.Correct Answer: C,D 49 of 60Question: 50Which statements of the event listener are true?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.Explanation:One component can registers one or more listeners. One listener can be registered by multiple components. After being registered the listener can receive and process the events from these components.Correct Answer: A,C 50 of 60Question: 51What is the return value of the method in the event listener interface?A. intB. StringC. voidD. ObjectE. AWTEventExplanation:All the methods in the event listener interfaces return void.Correct Answer: C 51 of 60Question: 52Which of the following event listeners have event adapters defined in Java?A. MouseListenerB. KeyListenerC. ActionListenerD. ItemListenerE. WindowListenerExplanation:Four listeners don't have their corresponding event adapters. They are ActionListener, ItemListener, AdjustmentListener and TextListener.Correct Answer: A,B,E 52 of 60Question: 53Which one of the following methods is not related to the display of the applets?A. update()B. draw()C. repaint()D. paint()Explanation:The paint(), update() and repaint() are predefined methods in Java. They are related to the display of the applets.Correct Answer: B 53 of 60Question: 54Given the following definition:TextArea ta = new TextArea (Hello, 5, 5);Which statements are true?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.Explanation:The TextArea is constructed to a 5 row * 5 character text area. It cannot display multiple fonts. The strings are editable by default. The displayed width of a line is 5 characters, but the maximum number in a line is more than 5.Correct Answer: B,D 54 of 60Question: 55Which method can be used to add MenuBar to a Frame?A. setMenu()B. setMenuBar()C. add()D. addMenuBar()Explanation:MenuBar is added to a Frame by using the setMenuBar() method. The add() method is used to add components to containers. Correct Answer: B 55 of 60Question: 56Which are not containers in Java?A. ScrollPaneB. CanvasC. ScrollbarD. AppletE. DialogExplanation:Scrollbar and Canvas are not containers. The following classes are containers in Java: Panel, Window, ScrollPane, Dialog, Frame, Applet.Correct Answer: B,C 56 of 60Question: 57Which of the following method can be used to define a new thread class?A. implement the Runnable interfaceB. add a run() method in the classC. create an instance of ThreadD. extend the Thread classExplanation:Two methods can define a new thread class: to implement the Runnable interface or to extend the Thread class.Correct Answer: A,D 57 of 60Question: 58Which of the following I/O stream are node streams?A. FileInputStreamB. BufferedInputStreamC. PushbackInputStreamD. ByteArrayInputStreamExplanation:The FileInputStream and ByteArrayInputStream are node streams. The BufferedInputStream and PushbackInputStream are filter streams.Correct Answer: A,D 58 of 60Question:59Which of the following classes can handle the Unicode?InputStreamReaderBufferedReaderWriterPipedInputStreamExplanation:Java uses Unicode to represent strings and characters and Java provides 16 bit versions of streams to allow characters to be treated similarly. They are Reader, Writer and their subclasses.Correct Answer: A,B,C 59 of 60Question: 60Which classes are used to implement TCP/IP client and servers?A. ServerSocketB. ServerC. SocketD. DatagramPacketE. DatagramSocketExplanation:Use ServerSocket and Socket classes to implement the TCP/IP clients and servers. The DatagramPacket and DatagramSocket are used in the UDP-based network communication.Correct Answer: A,C 60 of 60。

相关文档
最新文档