Java程序设计基础本部(A)

更新时间:2023-07-12 22:54:44 阅读: 评论:0

Java程序设计基础本部(A)
湖南农业⼤学课程考核试卷
课程名称(全称):Java 程序设计基础(双语)课程代码:20638B3
考核时间:2010 年 11 ⽉5⽇试卷号: A 考核对象:信息⼯程07-1、信息⼯程07-2
1. Given the file FirstClass.java:
1: import java.*;
2: public c lass FirstClass{ }
3: public interface Second{ } 4: abstract c lass SecondClass{ }
What error w ill the compiler likely generate? ()
A. Package java not found in import.
B. None. The file will compile fine.
C. Public interface Second must be defined in a file c alled “Sec ond.java ”.
D. Public class FirstClass must be defined in a file called “FirstClass.java ”. 2. Which of the following class definitions are legal? ()
A. private class A{ }
B. final abstract class F{ }
C. abstract class E;
D. public class C{ } 3. Given the following code:
1:public class Century implements Runnable { 2: public void run( ){
3: for(int year=1990; year<2000; year++){ 4: try {Thread.sleep(1000);
5: }catch(InterruptedException e){ } 6: }
7: System.out.println(“Happy new millennium!”)} } 8:class CountUp{
9: public static void main(String args[]){ 10: Century ourCentury = new Century( ); 11: //…… 12:}}
You now wish to begin the thread from another class. Which is the proper code, placed in the class CountUp at line 11, to begin the thread ()
I 、Choo one correct answer (Total 40 points ,each question 2 points )
A. Thread t=new Thread(ourCentury);
龙首铜像B. Thread t=new Thread(this);
t.start( ); t.start( );
C. Thread t=new Thread(ourCentury);
D. Thread t=new Thread(this);
ourCentury.start( ); ourCentury.run( );
4. Assuming the array is declared as a class member, which of the following will declare an array and initialize it with five numbers? ()
A. Array a=new Array(5);大年是几号
B. int [] array;
dnf诱魔者加点
C. int array[]=new int[5];
D. int a []=new int(5);
5. Examine the following code:
1: class StringLiteral{
2: public static void main(String[] args){
3: String java= “Java”, va= “va”;
新年音乐
4: System.out.print( java== “Java” );
5: System.out.print( java==( “Ja”+va ) );
6: System.out.print( java.equals( “Ja”+va ));
7: } } ()
A. true true true
B. true fal true
C. true true fal
D. fal true true
6. Complete the following ntence.
finally claus ().
A. are executed only after a try block executes with no exceptions
B. are only executed if an exception is thrown but no matching catch clau is found.
C. are always executed after try and catch blocks.
D. are only executed if a catch clau is executed in the current method.水底鱼
7. Which of the following is not a benefit of encapsulation ? ( )
A. Clarity of code
B. Code efficiency
C. The ability to add functionality later on
D. Modification requires less coding changes
8. What does a Java programmer have to do in order to relea an object that is no longer needed?
()
A. U the delete statement.
B. Call the finalize( ) method for the object.
C. ( ).
D. Nothing.
9. Which of the following assignment is not correct? ()
A. double f = 11.1;
B. double d = 5.3E12;
C. double d = 3.14159;
D. float d = 3.14.
10. Given the uncompleted code of a class:
1: public class A{
2: public void baz( ){
3: System.out.println(“A”);}}
4: public class B extends A{
5: public static void main(String[] args){
6: A a=new B( );
7: a.baz( );}
8: public void baz( ){
9: System.out.println(“B”);}}
What will happen when you compile and run this program? ()
A. The program compiles, runs, and displays A in the standard output.
B. The program compiles, runs, and displays B in the standard output.
C. The program compiles, but throws a runtime exception.
D. The program does not compile.
11. Of the following objects, which can not have locks ?()
A. Thread objects
B. Runnable Objects
C. Primitive types
D. Object objects
12. Given the following code:
1:import java.io.*;
2:public class Inventory{
3:public static void main(String[] args) throws IOException{
4:FileInputStream inFile= new FileInputStream(“surplus.dat”);
5:DataInputStream inData= new DataInputStream( inFile );
6:String s= adUTF( );
7:System.out.println( s );
8:inData.clo( ); }
9:}
Assume there is a file in the current directory called “ surplus.dat ” that contains a string of Unicode characters. What will happen if you attempt to compile and run this block of code?
()
A. The file will not compile.
B. The file will compile, but the class will generate an error when run.
C. The class will run and overwrite the file called “ surplus.dat ” and then it will overwrite all
data in the file.
D. The class will run and read-in the first line of UTF characters as a string, then display it on
the screen.
13. Assume you have an object that is ud to contain two values: a and b. Which of the following methods in its class can prevent concurrent access problems? ()
A. public int read(int a, int b){ return a+b; }
public void t(int a, int b){ this.a=a; this.b=b;}
B. public synchronized int read(int a, int b ){return a+b;}
public synchronized void t(int a, int b){ this.a=a; this.b=b;}
C. public int read(int a, int b){ synchronized(a){ return a+b; }}
public void t(int a, int b){ synchronized(b){ this.a=a; this.b=b;}}
D. public synchronized synchronized(this) int read(int a, int b ){return a+b;}
public synchronized synchronized(this) void t(int a, int b){ this.a=a; this.b=b;}
14. What is the default layout manager for a Panel container? ()
A. FlowLayout
B. BorderLayout
C. GridLayout
D. CardLayout
15. Which modifier is NOT legal in Java? ( )
A. private
B. public
C. protected
D. protect
16. Given the following code:
import java.awt.event.*;
import java.awt.*;
class Test implements ...{
// do something }
Which listeners must be inrted in the place ... to enable the program to pick up ActionEvent and WindowEvent? ()A. ActionListener
B. WindowListener
C. ActionListener,WindowListener
D. ActionListener,ContainerListener
17. What is the main task that java command in JDK does? ()
A. Executes code
B. V erifies code
C. Loads code
D. Compiles code
18. Given the follow ing command to run a correct c lass:
java MyTest a b c
Which statement is true? ( )
A. args[0] = MyTest a b c
健身计划表B. args[0] = MyTest
C. args[0] = a
D. arg s[1]= “b”
19. Given the follow ing code:
1: int I=0;
2: outer:
3: while( true ){
4: I++;
5: inner:侯莫陈
6: for (int j=0; j<10; j++){
7: I+=j;
8: if ( j == 3)
上海大学就业9: continue inner;
10: break outer;}
11: continue inner;}
12: System.out.println ( “I is”+I );
What w ill be the value of I when it is printed? ( )
A. 1 ;
B. 2;
C. 3 ;
D. 4 ;
20. Which statement can be compiled correctly:( )
A. import java.awt.*;

本文发布于:2023-07-12 22:54:44,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/1079028.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:考核   课程   基础   农业
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图