站内搜索
Java认证考试综合练习 问题列表
问题
单选题程序: class MyDate{ private int year; private int month; private int day; public MyDate( int year, int month,int day){ this.year=year; this.month=month; this.day=day; } //Override Method } 为了让new MyDate(1980,11,9)==(判断是否相等)new MyDate(1980,11,9) 返 回true,必须在Override Method处覆盖哪个方法?()A
hashCodeB
equalsC
toStringD
notify
问题
单选题现有: class TestMain { static int x = 2; static { x = 4; } public static void main(String... args) { int y = x + 1; System.out.println(y); } } 和命令行: java TestMain 结果为:()A
3B
5C
编译失败D
运行时异常被抛出
问题
单选题现有: class Parser extends Utilis { public static void main (String [] args) { try { System. out.print (new Parser ( ) .getlnt ("42")} ; } catch (NumberFormatException n) { System.out .println ( "NFExc" ) ; } } int getlnt (String arg) throws NumberFormatException{ return Integer.parselnt (arg) ; } class Utils { int getlnt (String arg) { return 42; } } 结果为 :()A
NFExcB
42C
42NFExcD
编译失败
问题
多选题现有: class Waiting implements Runnable { boolean flag=false; public synchronized void run() { if (flag) { flag=false; System.out.print ("1"); try { this.wait(); ) catch (Exception e) { } System.out.print ("2"); } else { flag=true; System.out.print ("3"); try{Thread.sleep (2000); } catch(Exception e) {} System.out.print ("4"); notify(); } } public static void main (String [] args) { Waiting w=new Waiting(); new Thread (w) .start(); new Thread (w) .start(); } } 以下哪两项是正确的?()A代码输出l 3 4B代码输出3 4 1C代码输出l 2 3 4D代码输出1 3 4 2E代码运行完毕F代码不会完成
问题
单选题类Student的声明如下: package com.school class Student{ String name; int age; Student(String name,int age){ //code } void study(String subject){ / /code } } 正确调用方法study(String subject)的是哪项?()A
Student stu = new Student(“Tom”,23); stu.study(“数学”);B
Student.study(“数学”);C
Student stu = new Student(“Tom”,23); stu.study();D
Student stu = new Student(“Tom”,23); String result=stu.study(“数学”);
问题
单选题volatile关键字的说法错误的是()。A
能保证线程安全B
volatile关键字用在多线程同步中,可保证读取的可见性C
JVM保证从主内存加载到线程工作内存的值是最新的D
volatile能禁止进行指令重排序
问题
单选题在java中.在使用JDBC时。对于多次调用同一条SQL语句的情况,使用()通常会提高效。A
StatementB
CallableStatementC
PreparedStatementD
PrarmeterStatement
问题
单选题为了使得System.out.println()输出对象引用的时候得到有意义的信息,我们应该覆盖Object中的哪个方法?()A
equalsB
hashCodeC
toStringD
notify
问题
单选题现有: class Pencil { public void write (String content){ System.out.println ("Write"+content); } } class RubberPencil extends Pencil{ public void erase (String content){ System.out.println ("Erase"+content); } } 执行下列代码的结果是哪项?() Pencil pen=new RubberPencil(); pen.write ("Hello"); pen.erase ("Hello");A
Write Hello Erase HelloB
Erase Hello Write HelloC
编译错误D
运行时抛出异常
问题
单选题class TestMain { static int x = 2; static { x = 4; } static public void main(String[] args) { int y = x + 1; System.out.println(y); } } 和命令行: java TestMain 结果为:()A
3B
5C
编译失败D
运行时异常被抛出
问题
单选题在文件读,写完毕之后是否需要关闭文件?()A
必须关闭,否则会无法完成文件读,写操作B
应当关闭,虽然无用对象回收机制会在回收文件读写对象时自动关闭,但对象回时间不定,因此应当及时调用文件读,写。C
不用关闭,Java在一次读,写操作完毕之后立即自动关闭文件D
不用关闭,Java在进行读写操作时不需要打开文件,因此也不用关闭文件
问题
单选题程序: class TestApp{ public static void main() String[] args){ for(int i=0;i10;i++){ if(i==3) break; 当循环到3时,自动跳出 System.out.print(i); } } } 程序运行后的输出是哪项?()A
0123B
012C
0123456789D
012456789