Java基础练习二
更新时间:2024-03-22 15:17:01 阅读量: 综合文库 文档下载
C 8. class A implements Runnable{ int i;
public void run(){ try{
Thread.sleep(5000); i=10;
}catch(InterruptException e){} }
public static void main(String[] args) { try{
a=new A();
Thread t=new Thread(a); t.start(); 14) int j=i; 16)
}catch(Exception e){} } }
在第 14 行加上哪些代码才能保证在第 16 行时 j=10? (单选) A.wait(); B.t.wait(); C.t.join(); D.t.yield(); E.t.notify();
A 2. 考察以下陈述:
陈述 A:属性定义类的特征。
陈述 B:行为定义类所执行的动作。 关于这些陈述,以下中哪个是正确的? A 两个陈述都为真。 B 两个陈述都为假。
C 陈述 A 为真,陈述 B 为假。
D 陈述 A为假,陈述 B 为真。 (单选) (答题时限:00:00:30)
D 3. 11. for (int i =0; i <3; i++) { 12. switch(i) { 13. case 0: break;
14. case 1: System.out.print(“one “); 15. case 2: System.out.print(“two “); 16. case 3: System.out.print(“three “); 17. } 18. }
19. System.out.println(“done”);
What is the result? (单选) A.done
B.one two done
C.one two three done
D.one two three two three done E.Compilation fails.
A 4. 11. public void test(int x) { 12. int odd = x%2; 13. if (odd) {
14. System.out.println(“odd); 15. } else {
16. System.out.println(“even”); 17. } 18. }
Which statement is true? (单选) A.Compilation fails.
B.“odd” will always be output. C.“even” will always be output.
D.“odd” will be output for odd values of x, and “even” for even values. E.“even” will be output for add values of x, and “odd” for even values.
A 5. 为把文件指针设置为文件内的特定位置,你将使用以下RandomAccessFile 类方法中哪个?
(单选) (答题时限:00:00:30) A.void seek(long pos)
B.long getFilePointer()
C.long length()
D.Byte [] readBytes(long)
B 6. You want to limit access to a method of a public class to members of the same class. Which access accomplishes this objective? (单选) A.public B.private C.protected D.transient
E.default access
D 7. Math类所在的包位置为( )。 (单选) A.java.awt.*; B.java.io.* C.java.sql.*;
D.java.lang.*
B 8. 1. public class Test {
2. private static float[] f = new float[2]; 3. public static void main(String args[]) { 4. System.out.println(“f[0] = “ + f[0]); 5. }
8. 1. public class Test {
2. private static float[] f = new float[2]; 3. public static void main(String args[]) {4. System.out.println(“f[0] = “ + f[0]); 5. } 6. }
What is the result? (单选) A.f[0] = 0 B.f[0] = 0.0
C.Compilation fails.
D.An exception is thrown at runtime.
C 1. 执行完下面的程序段后,k的值为( )。 int k=0;
label:for(int i=1;i<3;i++) {
for(int j=1;j<3;j++) {
k+=i+j;
System.out.println(k); if(i==2) continue label; }
} (单选) A.3 B.5 C.8 D.12
2. 1. public interface Foo { 2. int k = 4; 3. }
Which three are equivalent to line 2? (Choose three) A.final int k = 4; B.public int k = 4; C.static int k = 4; D.abstract int k = 4; E.volatile int k = 4; F.protected int k = 4;
(多选)
★标准答案:A,B,C
答题结果:正确! 答题结果:错误!
A,B 3. 下面关于线程的说法正确的是( )。 (多选) A.Java支持多线程机制 B.一个线程创建并启动后,它将执行自己的run()方法,如果通过派生Thread类实现多线程,则需要在子类中重新定义run()方法,把需要执行的代码写入run()方法中;如果通过实现Runnable接口实现多线程,则需要编写接口中的抽象方法——run()方法的方法体。 C.要在程序中实现多线程,必须导入Thread类:import java.lang.Thread;
D.一个程序中的主类不是Thread的子类,该类也没有实现Runnable接口,则这个主类运行不能控制主线程的休眠。
A 4. import java.io.IOException; public class ExceptionTest {
public static void main(String args[]) { try {
methodA(); }
catch(IOException e)
{ System.out.println(\} }
public void methodA() {
throw new IOException(); } }
结果是( )? (单选) A.代码不能编译。
B.输出是\ C.输出是 Caught IOException
D.程序正常执行,但没有打印信息。
D 5. 11. int i =1,j =10; 12. do {
13. if(i++> --j) { 14. continue;
15. }
16. } while (i <5);
17. System.out.println(“i = “ +i+ “and j = “+j); What is the result? A. i = 6 and j = 5 B. i = 5 and j = 5 C. i = 6 and j = 5 D. i = 5 and j = 6
E. i = 6 and j = 6 (单选) A.i = 6 and j = 5 B.i = 5 and j = 5 C.i = 6 and j = 5 D.i = 5 and j = 6 E.i = 6 and j = 6
D 6. Math类所在的包位置为( )。 (单选) A.java.awt.*; B.java.io.* C.java.sql.*; D.java.lang.*
A,B,C 7. 定义主类的类头时可以使用的关键字是( )。 A.abstract B.final C.public D.super
A 8. 下面代码的运行输出结果是( )。 public class example {
public static void main(String args[]) {
int x=0; if(x>0) x=1; switch(x) {
case 1: System.out.print(1); case 0: System.out.print(0); case 2: System.out.print(2); break;
case 3: System.out.print(3); default:System.out.print(4); break; }
(多选)
}
} (单选) A.02 B.43 C.23 D.10
1. 考察客户程序内所写的以下代码片段:
PrintStream out=new PrintStream(clientSocket.getOutputStream()); 为引用上面代码片段,考察以下陈述:
陈述 A:用PrintStream 对象从socket中读入。
陈述 B:getOutputStream() 方法提供了对server socket输出流的引用,并使客户与server通信。
关于这些陈述,以下中哪个为真? (单选) (答题时限:00:00:30) A.陈述 A 为真,陈述 B 为假。
B.陈述 A为假,陈述 B 为真。
C.陈述 A和 B都为真。 D.陈述 A和 B都为假。
★标准答案:B
2. class A implements Runnable{ int i;
public void run(){ try{
Thread.sleep(5000); i=10;
}catch(InterruptException e){} }
public static void main(String[] args) { try{
a=new A();
Thread t=new Thread(a); t.start(); 14) int j=i; 16)
}catch(Exception e){}
} }
在第 14 行加上哪些代码才能保证在第 16 行时 j=10? (单选) A.wait(); B.t.wait(); C.t.join(); D.t.yield(); E.t.notify();
★标准答案:C 3. 考察以下陈述:
陈述 A:用输入流把数据写出到文件或标准输入设备。 陈述 B: 流支持通信路径中数据的双向流动。
关于这些陈述,以下中哪个是正确的? (单选) (答题时限:00:00:30) A.陈述 A 为真,陈述 B 为假。 B.陈述 A为假,陈述 B 为真。 C.
陈述 A和 B都为真。 D.陈述 A和 B都为假。
★标准答案:D
4. int i=1,j=10; do{
if(i>j)continue; j--;
}while(++i<6);
经过上面的代码后,i 和 j 的值是( )? (单选) A.i=6,j=5 B.i=5,j=5 C.i=6,j=4 D.i=5,j=6
★标准答案:A
5. import java.awt.*;
public class X extends Frame
{
public static void main(String[] args) {
X x=new X(); x.pack();
x.setVisible(true); }
public X() {
setLayout(new BorderLayout()); Panel p=new Panel();
add(p,BorderLayout.NORTH); Button b=new Button(\p.add(b);
Button b1=new Button(\add(b1,BorderLayout.SOUTH); } }
下面哪两个是正确的( )? (多选)
A.标有\和\的两个按钮具有相同的宽度。 B.标有\和\的两个按钮具有相同的高度。 C.标有\的按钮的高度可以随窗口的大小而改变。 D.标有\的按钮的宽度不随窗口的大小而改变。
★标准答案:B,D
6. 编译Java Applet 源程序文件产生的字节码文件的扩展名为( )。00:00:30) A.java B.class C.html D.exe
★标准答案:B
8. 考察以下陈述:
陈述 A:属性定义类的特征。
陈述 B:行为定义类所执行的动作。 关于这些陈述,以下中哪个是正确的? A 两个陈述都为真。
(答题时限: (单选)
B 两个陈述都为假。
C 陈述 A 为真,陈述 B 为假。
D 陈述 A为假,陈述 B 为真。 (单选) (答题时限:00:00:30) A. B. C. D.
★标准答案:A
2. 现有整型数组int a[]={10,21,28,-3,84,55};,为了打印输出数组的各个元素,下面正确的代码是( )。 (多选) A.for(int i=0;i<=6;i++) System.out.println(a[i]); B.for(int i=0;i<6;i++) System.out.println(a[i]);
C.for(int i=0;i System.out.println(a(i)); D.for(int i=0;i System.out.println(a[i]);
★标准答案:B,D
3. 下面哪个阻止创建子类? (单选) A.static class FooBar{} B.private class Foobar{} C.abstract class FooBar{} D.final publiclass FooBar{}
★标准答案:D
4. 如果在条件求值前循环体至少要执行一次,应使用以下中( )? (单选) (答题时限:00:00:30) A.for B.while C.do…while D.switch...case
★标准答案:C
5. 编写应用程序,找出所有的水仙花数并输出。水仙花数是三位数,它的
各位数字的立方和等于这个三位数本身,例如 371就是一个水仙花数. (操作) (答题时限:00:10:00)
★标准答案:public class Narcissus {
public static void main(String[] args) { for(int i=100;i<1000;i++) {
int bai=i/100;
int shi=(i-bai*100)/10; int ge=i;
if((Math.pow(bai,3)+Math.pow(shi,3)+Math.pow(ge,3))==i) {
System.out.println(i+\是水仙花数.\} } } }
6. 1. public class Outer{
2. public void someOuterMethod() { 3. // Line 3 4. }
5. public class Inner{}
6. public static void main( String[]argv ) { 7. Outer o = new Outer(); 8. // Line 8 9. } 10. }
Which instantiates an instance of Inner? (单选) A.new Inner(); // At line 3 B.new Inner(); // At line 8 C.new o.Inner(); // At line 8 D.new Outer.Inner(); // At line 8
★标准答案:A
8. 给定下面的代码,编译运行结果将是( )。 public class TestVar {
public static void main(String [] args) { int x; x=x+1;
System.out.println(\}
} (单选) A.x is 1 B.x is +1
C.x is (某个不能确定的数值) D.编译失败
★标准答案:D
1. 1. public class ReturnIt {
2. return Type methodA(byte x, double y) { 3. return (short)x / y * 2; 4. } 5. }
What is the narrowest valid returnType for methodA in line2? A.int B.byte C.long D.short E.float F.double
★标准答案:F
2. java.awt.*抽象工具包下面提供了( )类。 (多选) A.创建用户界面的GUI组件 B.事件处理的模型
C.排列图形组件的布局管理器 D.创建线程的类和接口
(单选)
★标准答案:A,C
答题结果:正确! 答题结果:错误! 3. 11. int i = 0; 12. while (true) { 13. if(i==4) { 14. break; 15. } 16. ++i; 17. }
18. System.out.println(“i=”+i); What is the result? (单选) A.i = 0 B.i = 3 C.i = 4 D.i = 5
E.Compilation fails.
★标准答案:C
4. 以下选项中变量均已正确定义,合法的赋值语句是( )。 (单选) A.a==1 B.++i
C.a=a+1=5 D.y=int(i)
★标准答案:B
5. 定义一个类Point,类中有两个double型变量x和y,对于其构造函数的声明正确的是( )。 (多选)
A.Point Point(int x) {…} B.public Point(int x) {…}
C.public Point(int x,int y) {…} D.public Point(Point p) {…}
★标准答案:B,C,D
答题结果:正确! 答题结果:错误! 6. 1. interface Animal { 2. void soundOff(); 3. } 4.
5. class Elephant implements Animal { 6. public void soundOff() {
7. System.out.println(“Trumpet”); 8. } 9. } 10.
11. class Lion implements Animal { 12. public void soundOff() { 13. System.out.println(“Roar”); 14. } 15. } 16.
17. class Alpha1 {
18. static Animal get( String choice ) {
19. if ( choice.equalsIgnoreCase( “meat eater” )) { 20. return new Lion(); 21. } else {
22. return new Elephant(); 23. } 24. } 25. }
Which compiles? (单选) A.new Animal().soundOff(); B.Elephant e = new Alpha1();
C.Lion 1 = Alpha.get(“meat eater”);
D.new Alpha1().get(“veggie”).soundOff();
★标准答案:D
7. 11. public void test(int x) { 12. int odd = x%2; 13. if (odd) {
14. System.out.println(“odd); 15. } else {
16. System.out.println(“even”); 17. } 18. }
Which statement is true? (单选) A.Compilation fails.
B.“odd” will always be output. C.“even” will always be output.
D.“odd” will be output for odd values of x, and “even” for even values. E.“even” will be output for add values of x, and “odd” for even values.
★标准答案:A
1. Applet类的( )方法返回字节码文件所处的位置。 (单选) A.getCodeBase() B.getURL() C.getPath()
D.getDocumentBase()
★标准答案:A 3.
12. void start() { 13. A a = new A(); 14. B b = new B(); 15. a.s(b); 16. b = null; 17. a = null;
18. System.out.println(“start completed”); 19. }
When is the B object, created in line 14, eligible for garbage collection? A.After line 16. B.After line 17.
C.After line 18 (when the methods ends). D.There is no way to be absolutely certain.
E.The object is NOT eligible for garbage collection.
★标准答案:D
(单选)
答题结果:正确! 答题结果:错误!
4. Which statement is true about assertion in the Java programming language? (单选) A.Assertion expressions should not contain side effects. B.Assertion expression values can be any primitive type.
C.Assertion should be used for enforcing preconditions on public methods.
D.An AssertionError thrown as a result of a failed assertion should always be handled by the enclosing method.
★标准答案:A
5. 线程处于等待队列的时候,可以用什么方法让所有线程回到运行状态( )? (单选) (答题时限:00:00:30) A.Notify
B.Notifyall C.Resume
D.Suspend
★标准答案:B
6. 下面哪个方法不属于InputStream类。 (单选) A.int read(byte[]) B.void flush() C.int read() D.void close() E.int available()
★标准答案:B
7. 11. double d = Math.random();
Which is true about dafter line 11? (单选) A.d >= 1.0
B.0.0 <= d < 1.0
C.0.0 <= d < Double.MAX_VALUE D.0.0 <= d <= Double.MAX_VALUE
E.Double.MIN_VALUE <= d < Double.MAX_VALUE
★标准答案:B
8. 1. abstract class AbstractIt { 2. abstract float getFloat(); 3. }
4. public class AbstractTest extends AbstractIt { 5. private float f1 = 1.0f;
6. private float getFloat() { return f1; } 7. }
What is the result? (单选) A.Compilation succeeds. B.An exception is thrown.
C.Compilation fails because of an error at line 2. D.Compilation fails because of an error at line 6.
★标准答案:D
1. 1. public class Test {
2. public static void main(String Args[]) { 3. int i =1, j = 0; 4. switch(i) { 5. case 2: j +=6; 6. case 4: j +=1; 7. default: j +=2; 8. case 0: j +=4; 9. }
10. System.out.println(“j =” +j); 11. } 12. }
What is the result? (单选) A.0 B.2 C.4 D.6 E.9 F.13
★标准答案:D
2. 下面哪个正确的构建了一个 DataOutputStream? (单选) A.new DataOutputStream(\
B.new DataOutputStream(new File(\
C.new DataOutputStream(new FileWriter(\
D.new DataOutputStream(new FileOutputSream(\
★标准答案:D
3. 设有定义语句:int a[]={66,88,99};则关于该语句的叙述错误的是( )。 (单选) A.定义了一个名为a的一维数组 B.a数组有3个元素 C.a数组的下标为1~3
D.数组中的每个元素数据类型是int型
★标准答案:C
4. Which two cause a compiler error? (Choose two) (多选) A.int[] scores = {3, 5, 7};
B.int [][] scores = {2,7,6}, {9,3,45};
C.String cats[] = {“Fluffy”, “Spot”, “Zeus”};
D.boolean results[] = new boolean [3] {true, false, true};
E.Integer results[] = {new Integer(3), new Integer(5), new Integer(8)};
F.String[] dogs = new String[]{new String(“Fido”),new String(“Spike”), new String(“Aiko”)};
★标准答案:B,D
5. Which three statements are true? (Choose three) (多选)
A.Assertion checking is typically enabled when a program is deployed.
B.It is never appropriate to write code to handle failure of an assert statement.
C.Assertion checking is typically enabled during program development and testing.
D.Assertion checking can be selectively enabled or disable an a per-package basis, but not on a per-class basis.
E.Assertion checking can be selectively enabled or disabled on both a per-package basis and a per-class basis.
★标准答案:B,C,E
6. 下列( )类可以作为FileInputStream类的构造方法的参数。 (多选) A.InputStream B.File
C.FileOutputStream D.String
E.(File file, String x)
★标准答案:B,D
7. 要将MenuBar加入一个Frame中,应使用的方法是( )。 (单选) A.setMenu() B.setMenuBar() C.add()
D.addMenuBar()
★标准答案:B
Java Application源程序的主类是指包含有( )方法的类。 (单选) (答题时限:00:00:30) A.main方法 B.toString方法 C.init方法
D.actionPerfromed方法
★标准答案:A
1. public class X{ public Object m(){
3) Object o=new Float(3.14f); 4) Object[] oa=new Object[1]; 5) oa[0]=o; 6) o=null;
7) return oa[0]; } }
在第 3 行创建的 Float 对象,什么时候可以垃圾回收? (单选) A.第 5 行后 B.第 6 行后 C.第 7 行后
D.在本方法中不会被回收
★标准答案:D
2. 1. package test1; 2. public class Test1 { 3. static int x = 42; 4. }
1. package test2;
2. public class Test2 extends test1.Test1 { 3. public static void main(String[] args) { 4. System.out.println(“x = “ + x); 5. } 6. }
What is the result? (单选) A.x = 0 B.x = 42
C.Compilation fails because of an error in line 2 of class Test2. D.Compilation fails because of an error in line 3 of class Test1. E.Compilation fails because of an error in line 4 of class Test2.
★标准答案:C
3. 1. package foo;
2. public class Outer { 3. public static class Inner { 4. } 5. }
Which statement is true? (单选) A.Compilation fails.
B.An instance of the Innerclass can be constructed with “new Outer.Inner()”. C.An instance of the Inner class cannot be constructed outside of package foo.
D.An instance of the Inner class can be constructed only from within the Outer class.
E.From within the package foo, and instance of the Innerclass can be
constructed with “new Inner()”.
★标准答案:B
4. 当一个程序中含有下列语句,那个必须放在程序第一行( )。 (单选) A.package aa; B.import java.io.*; C.class Exam
D.以上语句可以随意放置,没有一定的顺序
★标准答案:A
5. 若a的值为3时,下列程序段被执行后,c的值是多少?( ) c = 1;
if ( a>0 ) if ( a>3 ) c = 2; else c = 3; else c = 4; (单选) (答题时限:00:00:30) A.1 B.2 C.3 D.4
★标准答案:C
6. Which statement is true? (单选)
A.To call the wait() method, a thread most own the lock of the current thread.
B.To call the wait() method, a thread must own the lock of the object on which the call is to be made.
C.To call the join() method, a thread must own the lock of the object on which the call is to be made.
D.To call the sleep() method, a thread must own the lock of the object which the call is to be made.
E.To call the yield() method, a thread must own the lock of the object on which the cal is to be made.
★标准答案:B
7. 下列程序段执行后,t3的结果是( )。 int t1=2,t2=3,t3; t3=t1 A.2 B.4 C.5 D.6
★标准答案:A
1. Which three statements are true? (Choose three) (多选)
A.Assertion checking is typically enabled when a program is deployed.
B.It is never appropriate to write code to handle failure of an assert statement.
C.Assertion checking is typically enabled during program development and testing.
D.Assertion checking can be selectively enabled or disable an a per-package basis, but not on a per-class basis.
E.Assertion checking can be selectively enabled or disabled on both a per-package basis and a per-class basis.
★标准答案:B,C,E
2. 1. class MyThread extends Thread {
2. public void run() { System.out.println(“AAA”); }
3. public void run(Runnable r) { System.out.println(“BBB”); } 4.
5. public static void main(String[] args) { 6. new Thread(new MyThread()).start(); 7. } 8. }
What is the result? (单选) A.AAA B.BBB
C.Compilation fails.
D.The code runs with no output.
★标准答案:A
4. 下列语句序列执行后,j的值是( )。
int j=3,i=2; while(--i!=i/j) j=j+2; (单选) A.2 B.4 C.6 D.5
★标准答案:D
5. Which code determines the int value foo closest to, but not greater than, a double value bar? (单选) (答题时限:00:00:30) A.Int foo = (int) Math.max(bar); B.Int foo = (int) Math.min(bar); C.Int foo = (int) Math.abs(bar); D.Int foo = (int) Math.ceil(bar); E.Int foo = (int) Math.floor(bar); F.Int foo = (int) Math.round(bar);
★标准答案:E
6. 下面说法正确的是( )。 (单选)
A.Java程序的源文件名称与主类(公共类)的名称相同,后缀可以是java或txt等 B.JDK的编译命令是java
C.一个Java源程序编译后可能产生几个字节码文件
D.在命令行运行编译好的字节码文件,只需在命令行直接键入程序名即可运行该程序
★标准答案:C 7.
1. package foo; 2.
3. import java.util.Vector; 4.
5. private class MyVector extends Vector { 6. int i = 1;
7. public MyVector() { 8. i = 2;
9. } 10. } 11.
12. public class MyNewVector extends MyVector { 13. public MyNewVector() { 14. i = 4; 15. }
16. public static void main(String args[]) { 17. MyVector v = new MyNewVector(); 18. } 19. }
What is the result? (单选) A.Compilation succeeds.
B.Compilation fails because of an error at line 5. C.Compilation fails because of an error at line 6. D.Compilation fails because of an error at line 14. E.Compilation fails because of an error at line 17.
★标准答案:B
8. 定义类Calcu,构造方法为默认构造方法。利用方法重载定义三个方法add,分别完成一个整型操作数的加1,两个整型操作数的相加,和三个实型操作数的相加,add方法都需要有返回值,在此类中定义主方法,在主方法中定义操作数变量,调用不同的add方法实现不同数值的运算并输出结果。
(操作) (答题时限:00:10:00)
★标准答案:public class Calcu {
public Calcu() { }
public int add(int oper) {
oper+=1; return oper; }
public int add(int oper1,int oper2) {
return oper1+oper2;
}
public double add(double ope1,double ope2,double ope3) {
return ope1+ope2+ope3; }
public static void main(String[] args) { Calcu cal=new Calcu(); int oper=45;
System.out.println(oper+\int oper1=78,oper2=987;
System.out.println(oper1+\double ope1=78.9,ope2=89.2,ope3=56.3;
System.out.println(ope1+\ } }
1. Thread Z holds the lock on object A. Thread X is blocked inside a wait call on ObjectA. What allows thread X to become runnable? (单选) A.Thread X is interrupted. B.Thread X is interrupted.
C.Thread X’s wait() times out. D.Thread Z calls Thread.sleep(100);
E.Thread Z releases the lock on A and calls the notify() method on thread X.
F.Thread Z releases the lock on A and calls the notifyAll() method on objectA.
★标准答案:F
2. 下面那个方法不是InputStream类中的方法? A int read(byte[]) B void flush() C void close()
D int available() (单选) (答题时限:00:00:30) A. B. C. D.
★标准答案:B
3. Hashtable 实现了哪个接口? (单选) A.java.util.Map B.java.util.List
C.java.util.Hashable D.java.util.Collection
★标准答案:A
4. Which method is an appropriate way to determine the cosine of 42 degrees? (单选) (答题时限:00:00:30) A.Double d = Math.cos(42); B.Double d = Math.cosine(42);
C.Double d = Math.cos(Math.toRadians(42)); D.Double d = Math.cos(Math.toDegrees(42)); E.Double d = Math.cosine(Math.toRadians(42));
★标准答案:C
5. Which two are valid declarations of a float? (Choose two) (多选) A.float f = 1F; B.float f = 1.0.; C.float f = ‘1’; D.float f = “1”; E.float f = 1.0d;
★标准答案:A,C
6. 在一个Java源文件中定义了3个类和15个方法,编译该Java源文件时会产生( )个字节码文件,其扩展名是( )。 (单选) A.15 .java B.3 .java C.3 .class D.15 .class
★标准答案:C
7. Which three demonstrate an “is a” relationship? (Choose three) (多选) A.public class X { } public class Y extends X { }
B.public interface Shape { } public interface Rectangle extends Shape{ } C.public interface Color { } public class Shape { private Color color; } D.public interface Species { } public class Animal { private Species species; }
E.public class Person { } public class Employee { public Employee(Person person) { }
F.interface Component { } class Container implements Component { private Component[] children; }
★标准答案:A,B,F
8. 下列有关Java Applet程序类中的start方法的执行时机的描述,( )是正确的。 (多选) A.浏览器执行完init()方法之后,将自动调用start()方法 B.每当浏览器被用户最小化时,浏览器也将调用它。
C.用户离开本网页后,又回退掉当前网页时浏览器也将再次执行它。 D.每当浏览器从图标状态下恢复为窗口时,它也将被执行。
★标准答案:A,C,D
1. 下面的程序段输出的结果是( )。 int i=1,b,c;
int []a=new int [3]; b=a[i]; c=b+i;
System.out.println(c); (单选) A.0 B.2 C.1 D.4
★标准答案:C
2. 怎样计算 42 度角的余弦值? (单选) A.double d=Math.cos(42); B.double d=Math.cosine(42);
C.double d=Math.cos(Math.toRadians(42)); D.double d=Math.cos(Math.toDegrees(42)); E.double d=Math.toRadious(42);
★标准答案:C
3. 在下面指定位置添加( )选项中定义的方法,编译时会产生错误。 public class C extends B {
//此处添加选项中的方法 }
class B {
public float getNum() {
return 1.0f; }
} (单选)
A.public float getNum() { return 4.0f;}
B.public double getNum(float D) { return 3.0f;} C.public void getNum(double D) { } D.public void getNum() { }
★标准答案:D
4. You want to limit access to a method of a public class to members of the same class. Which access accomplishes this objective? (单选) A.public B.private C.protected D.transient
E.default access
★标准答案:B
5. 线程处于等待队列的时候,可以用什么方法让所有线程回到运行状态( )? (单选) (答题时限:00:00:30) A.Notify
B.Notifyall C.Resume
D.Suspend
★标准答案:B
6. 考察以下陈述:
陈述A: 用try块处理引发的异常。 陈述B: 用throw 关键字抛出异常。
陈述C: Throwable类是Java程序中可能出现的所有错误和异常的超类。 陈述D:try块后可接一个或多个finally块。 所给出的陈述中哪个为真?
(单选) (答题时限:00:00:30) A.A 和 B
B.B 和 C
C.C 和 D D.A 和 D
★标准答案:B
7. 为了让同一个包内其它类有权访问一个类的成员,以下哪个访问控制符最适合? (单选) A.public B.private C.protected
D.没有访问控制符
★标准答案:D
8. What happens when thread X executes a wait() method on object A, without owning object A’s lock? (单选) A.Compilation fails.
B.An exception is thrown.
C.The wait() method has no effect.
D.Thread X receives the lock immediately.
E.Object A moves the thread to the wait pool.
★标准答案:B
1. In which two cases does the compiler supply a default constructor for class A? (Choose two) (多选)
A.class A { }
B.class A { public A() {} } C.class A { public A(int x) {} }
D.class Z {} class A extends Z { void A() {} }
★标准答案:A,D
2. 下列语句序列执行后,r的值是( )。 int x=5,y=10,r=5; switch(x+y) {
case 15: r+=x; case 20: r-=y; case 25: r*=x/y; default: r+=r; } (单选) A.15 B.10 C.0 D.20
★标准答案:C
3. 下面哪个阻止创建子类? (单选) A.static class FooBar{} B.private class Foobar{} C.abstract class FooBar{} D.final publiclass FooBar{}
★标准答案:D
4. public class SuperClass {
class SubClass extends SuperClass{} public void test(SubClass foo){ 5) SuperClass bar=foo; } }
下面哪句是正确的? (单选) A.第 5 行的赋值是不合法的
B.第 5 行的赋值是合法的,但会抛出一个 ClassCastException C.上面的代码是合法的,而且执行时不会抛出异常。
★标准答案:C 5.
1. package foo; 2.
3. import java.util.Vector; 4.
5. private class MyVector extends Vector { 6. int i = 1;
7. public MyVector() { 8. i = 2; 9. } 10. } 11.
12. public class MyNewVector extends MyVector { 13. public MyNewVector() { 14. i = 4; 15. }
16. public static void main(String args[]) { 17. MyVector v = new MyNewVector(); 18. } 19. }
What is the result? (单选) A.Compilation succeeds.
B.Compilation fails because of an error at line 5. C.Compilation fails because of an error at line 6.
E.Compilation fails.
★标准答案:E
6. 11. String a = “ABCD”; 12. String b = a.toLowerCase(); 13. b.replace(‘a’, ‘d’); 14. b.replace(‘b’, ‘c’); 15. System.out.println(b);
What is the result? (单选) (答题时限:00:00:30) A.abcd B.ABCD C.dccd D.dcba
E.Compilation fails.
F.An exception is thrown at runtime.
★标准答案:A
. 1.public class Mycircle { 2. public double radius; 3. public double diameter; 4.
5. public void setRadius(double radius) 6. this.radius = radius;
7. this.diameter= radius * 2; 8. } 9.
10.public double getRadius() { 11. return radius; 12. } 13. }
Which statement is true? (单选)
A.The Mycircle class is fully encapsulated.
B.The diameter of a given MyCircle is guaranteed to be twice its radius. C.Lines 6 and 7 should be in a synchronized block to ensure encapsulation.
D.The radius of a MyCircle object can be set without affecting its diameter.
★标准答案:B
8. 1. class Super 2. {
3. public float getNum(){return 3.0f;} 4. }
5. public class Su extends Super 6. { 7. 8. }
下面的哪个方法放在第 7 行将引起编译错误? (单选) A.public float getNum(){return 4.0f;} B.public void getNum(){}
C.public void getNum(double d){}
D.public double getNum(float d){return 4.0d;}
★标准答案:B
1. finally块中的代码将( )。 (单选) A.总是被执行
B.如果try块后面没有catch块时,finally块中的代码才会执行 C.异常发生时才被执行
D.异常没有发生时才被执行
★标准答案:A
2. 1) public class X{ 2) public Object m(){
3) Object o=new Float(3.14F); 4) Object[] oa=new Object[1]; 5) oa[0]=o; 6) o=null; 7) oa[0]=null;
8) System.out.println(oa[0]); 9) } 10) }
最早在第几行对象 o 就可以被垃圾回收? (单选)
A.第 4 行后 B.第 5 行后 C.第 6 行后 D.第 7 行后
E.第 9 行后(也就是说在方法结束后)
★标准答案:C
3. 11. public void test(int x) { 12. int odd = x%2; 13. if (odd) {
14. System.out.println(“odd); 15. } else {
16. System.out.println(“even”); 17. } 18. }
Which statement is true? (单选) A.Compilation fails.
B.“odd” will always be output. C.“even” will always be output.
D.“odd” will be output for odd values of x, and “even” for even values. E.“even” will be output for add values of x, and “odd” for even values.
★标准答案:A
4. 定义类A及类中的方法getVar(),定义类A的子类B,若要在类B中覆盖类A中的同名方法,下面正确的定义是( )。 class A {
private float x=1.0f; protected float getVar() {
return x; } }
class B extends A {
private float x=2.0f;
//覆盖类A中的同名方法的代码放在此处 } (单选)
A.float getVar() {return x;}
B.protected float getVar(float y) {return x+y;} C.protected float getVar() {return x;} D.public float getVar() {return x;}
★标准答案:C
5. 11. String a = null; 12. a.concat(“abc”); 13. a.concat(“def”);
14. System.out.println(a);
What is the result? (单选) (答题时限:00:00:30) A.abc B.null C.abcdef
D.Compilation fails.
E.The code runs with no output. F.An exception is thrown at runtime.
★标准答案:F 6.
11. int i = 1,j = 10; 12. do { 13. if(i>j) { 14. break; 15. } 16. j--;
17. } while (++i <5);
18. System.out.println(“i =” +i+” and j = “+j); What is the result? (单选) A.i = 6 and j = 5 B.i = 5 and j = 5 C.i = 6 and j = 4 D.i = 5 and j = 6 E.i = 6 and j = 6
★标准答案:D
7. 为把文件指针设置为文件内的特定位置,你将使用以下RandomAccessFile 类方法中哪个?
(单选) (答题时限:00:00:30) A.void seek(long pos)
B.long getFilePointer()
C.long length()
D.Byte [] readBytes(long)
★标准答案:A
8. Which three statements are true? (Choose three) (多选) A.The default constructor initializes method variables. B.The default constructor has the same access as its class.
C.The default constructor invoked the no-arg constructor of the superclass.
D.If a class lacks a no-arg constructor, the compiler always creates a default constructor.
E.The compiler creates a default constructor only when there are no other constructors for the class.
★标准答案:B,C,E
1. 考察以下代码: class Check {
public static void main(String args[]) {
int a,b=1;
System.out.println(b); for(a=0;a<=3;a++) {
b=10*b+1;
System.out.println(b); } } }
其输出将是什么?
★标准答案:D
. 执行完下面的程序段后,输出的结果是( )。 char c='\\0';
for(c='a';c<'z';c+=3) {
if(c>='d') break; }
System.out.println(\(单选) A.'e' B.'f' C.'a' D.'d'
★标准答案:D
6. 下列( )代码片断是正确的。 (多选) A.package testpackage;
public class Test{//do something……} B.import java.io.*; package testpackage;
public class Test{//do something……} C.import java.io.*;
class Person(){//do something……} public class Test{//do something……} D.import java.io.*; import java.awt.*;
public class Test{//do something……}
★标准答案:A,C,D
7. 1. class Test { 2. private Demo d; 3. void start() { 4. d = new Demo(); 5. this.takeDemo(d); 6. }
7.
8. void takeDemo(Demo demo) { 9. demo = null;
10. demo = new Demo(); 11. } 12. }
When is the Demo object, created on line 4, eligible for garbage collection? (单选) A.After line 5. B.After line 9.
C.After the start() method completes.
D.When the takeDemo() method completes.
E.When the instance running this code is made eligible for garbage collection.
★标准答案:E
8. 以下的变量定义中,合法的语句是( )。 (单选) A.float floatVariable=3.4 B.int abc_=21
C.double class1=1+4e2.5 D.short import=15
★标准答案:B
1. 考察以下代码: public class Bank {
String ID; String Name; int Age;
public Bank() { ID=\Name=\Age=26; }
public void display1() {
System.out.println(\
System.out.println(\ System.out.println(\ }
public static void main(String args[]) {
Bank bankObj=new Bank(); bankObj.display1(); } }
以下中哪个是上面应用的主线程( )? (单选) (答题时限:00:00:30) A.Bank 类
B.main() 方法 C.Bank 构造符 D.display() 方法
★标准答案:B
2. 执行下列程序段后,b,x,y的值正确的是( )。 int x=6,y=8; boolean b; b =x
A.true,6,8 B.false,7,7 C.true,7,7 D.false,6,8
★标准答案:C
3. 下面语句执行的结果( )? System.out.println( 4 | 3 );
(单选) (答题时限:00:00:30) A. 6 B. 0
C.1 D.7
★标准答案:D
4. 线程处于等待队列的时候,可以用什么方法让所有线程回到运行状态( )? (单选) (答题时限:00:00:30) A.Notify
B.Notifyall C.Resume
D.Suspend
★标准答案:B
5. Applet类的( )方法返回字节码文件所处的位置。 A.getCodeBase() B.getURL() C.getPath()
D.getDocumentBase()
★标准答案:A
6. Which method is an appropriate way todegrees? (单选) (答题时限:00:00:30) A.Double d = Math.cos(42); B.Double d = Math.cosine(42);
C.Double d = Math.cos(Math.toRadians(42)); D.Double d = Math.cos(Math.toDegrees(42)); E.Double d = Math.cosine(Math.toRadians(42));
★标准答案:C
7. 下面哪个阻止创建子类? (单选) A.static class FooBar{} B.private class Foobar{} C.abstract class FooBar{} D.final publiclass FooBar{}
determinethe cosineof 42 (单选)
★标准答案:D
8. 执行完下面的程序段后,i和j的值法分别为( )。 int j=10,i=1; do {
if(i++>--j)continue; }while(i<5) (单选) A.i=6 j=5 B.i=5 j=6 C.i=5 j=5 D.i=6 j=6
★标准答案:B
1. 下面关于子类和父类构造函数的描述中正确的是( )。 (多选) A.子类必须通过super关键字调用父类有参数的构造函数 B.子类必须通过this关键字调用父类的构造函数 C.子类无条件的继承了父类不含参数的构造函数
D.如果子类定义了自己的含参数的构造函数,就不能再调用父类的构造函数
★标准答案:A,C
2. 下面( )类可以作为File类的构造方法的参数。 (多选) A.String path
B.String path,String name C.File dir,String name D.File dir,File name
★标准答案:A,B,C
3. 下面那一个函数是线程的入口函数( )? (单选) (答题时限:00:00:30) A.private void stop() B.public void run()
C.public void start() D.public void begin()
正在阅读:
Java基础练习二03-22
一个练口语的经典方法07-01
11动医兽医微生物思考题06-30
德育(第二册)§2-2 做现代企业人教案 - 图文06-18
5&183;12护士节联欢会台词07-25
日记300字开学第一天11-20
2021年街道办事处年度工作总结及下一年工作计划部署08-03
线性赋范空间泛函有界性05-23
- 多层物业服务方案
- (审判实务)习惯法与少数民族地区民间纠纷解决问题(孙 潋)
- 人教版新课标六年级下册语文全册教案
- 词语打卡
- photoshop实习报告
- 钢结构设计原理综合测试2
- 2014年期末练习题
- 高中数学中的逆向思维解题方法探讨
- 名师原创 全国通用2014-2015学年高二寒假作业 政治(一)Word版
- 北航《建筑结构检测鉴定与加固》在线作业三
- XX县卫生监督所工程建设项目可行性研究报告
- 小学四年级观察作文经典评语
- 浅谈110KV变电站电气一次设计-程泉焱(1)
- 安全员考试题库
- 国家电网公司变电运维管理规定(试行)
- 义务教育课程标准稿征求意见提纲
- 教学秘书面试技巧
- 钢结构工程施工组织设计
- 水利工程概论论文
- 09届九年级数学第四次模拟试卷
- 练习
- 基础
- Java
- 周易的结构组成 - 图文
- 高一物理第七周周末练习
- 宣恩县中小学化学实验室安全守则
- 集团员工手册
- 2018-2019学年高一化学上学期周练5(无答案)(1) - 图文
- 《面向对象程序设计》实验指导书(选修)
- 中国液压升降平台行业发展研究报告 - 图文
- 沪教版-初中数学-整式的运算
- 数字化段修生产调度指挥系统 - 图文
- 实达终端培训资料 - 图文
- 重庆广播电视大学
- 计量经济学作业1
- 数字化图像的采集与加工学案
- 7.第七单元:元素周期表
- 拓展训练经典游戏30个 - 图文
- 星星书屋 - 图文
- 2019学年高一化学上学期周练5(无答案) 人教 新目标 版
- 2015年全国100所名校高三单元测试示范卷 化学卷12 电化学基础
- 作文教学论重点和难点
- 白眉姬鹟繁殖期鸣唱的声谱分析 - 图文