Java基础试题及其答案 联系客服

发布时间 : 星期二 文章Java基础试题及其答案更新完毕开始阅读

20) 在Java中,下列( )是不合法的赋值语句。(选择一项)

a) float f=1/3; b) int i=1/3; c) float f=1*3.0; d) double f=1.0/3;

21) 利用JAVA SWING 编程,要在当前窗体中显示如下信息提示框,则需要编写的代码

是( )。(选择一项)

a) JOptionPane.showMessageDialog(null,\请输入登陆名!\提示信

\

b) new JOptionPane.showMessageDialog(null,\请输入登陆名!\提示信

\

c) new JOptionPane.messageDialog(null,\请输入登陆名!\提示信

\

d) JOptionPane.messageDialog(null,\请输入登陆名!\提示信

\

22) 给定某java程序的main方法,如下;(选择一项)

public static void main(String [ ]args) { int i = 0; System.out.println(i++) ; }

a) 0 b) 1

c) 编译错误

d) 运行时出现异常

23)给定java程序,如下:编译运行Test.java,结果是( )。(选择一项)

public class Test{ private static final int counter=10; public static void main(String[] args) { System.out.println(++counter) ; } }

a) 10 b) 11

c) 编译错误

d) 运行时出现异常

24)在JAVA中,要创建一个新目录,要使用( )类的实例。(选择一项)

a) File

b) FileOutputStrean

5

息息息息

c) PrintWriter d) Dir

25) 在java 中,下列( ) 类不能派生出子类. (选择一项)

a) public class MyClass{ } b) class MyClass{ }

c) abstract class MyClass{ } d) final class MyClass { }

26) 在java 中,以下( )命令能够将java源文件编译为类文件 (选择一项)

a) java b) javaw c) javac d) jar

27)在JAVA中,通过调用以下( )方法,可以装载SUN的JDBC-ODBC桥。(选择一项)

a) new Class() .load(“sun.jdbc.odbc.jdbcodbcDriber”) ;

b) new Class() .forName(“sun.jdbc.odbc.JdbcOdbcDriver”) ; c) Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”) ; d) Class.load(“sun.jdbc.odbc.JdbcOdbcDriver”) ;

28) 在JAVA中,要判断D盘下是否存在文件abc.txt,应该使用以下( )判断语句。(选择一项)

a) if(new File(“d:abc.txt”) .exists() = =1) b) if(File.exists(“d:abc.txt”) = =1) c) if(new File(“d:/abc.txt”) .exists( ) ) d) if(File.exists(“d:/abc.txt))

29) 在JAVA接口中,下列选项里有效的方法声明是( )。(选择二项)

a) public void aMethod( ) ; b) void aMethod( ) ;

c) static void aMethod( ) ; d) protected void aMethod( ) ;

30) 给定JAVA代码,如下:编译运行,结果是( )。(选择一项)

public static void main(string[] args) { String s; System.out.println(“s=”+s) ; }

a) 编译错误

b) 编译通过,但出现运行是错误 c) 正常运行,输出s=null d) 正常运行,输出s=

31) 给定一个java程序的main方法的代码片段如下:假如d 目录下不存在abc.txt文件,现运行该程序,下面的结果正确的是( )。 ( 选择一项)

try {

PrintWriter out=new PrintWriter(new FileOutputStream(“d:/abc.txt”)) ;

6

String name=”chen”; out.print(name) ; out.close( ) ; }

catch(Execption e) {

System.out.println(“文件没有发现!“) ; }

a) 将在控制台上打印:“文件没有发现!” b) 正常运行,但没有生成文件abc.txt c) 运行后生成abc.txt ,但该文件中无内容 d) 运行后生成abc.txt,该文件内容为:chen

32) 在JAVA中,对于PreparedStatement的方法setInt(int i,int x) ,描述正确的是((选择一项)

a) 使得第i-1个参数的值设为x b) 使得第x-1个参数的值设为 i c) 使得第x个参数的值设为 i d) 使得第i个参数的值设为 x 33) 给定JAVA程序Test.java,如下:

package com; public class Test{

public void talk( ) { }

protected void walk( ) { } private void climb( ) { } private void jump( ) { } 给定Test的子类Test2,代码如下: Package com.util; Import com.*;

Public class Test2 extends Test {

Public static void main(String[] args) {

Test2 tt=new Test2( ) ; //A } }

可以在Test2的A处加入的代码是()。(选择二项) a) tt.talk( ) ; b) tt.walk( ) ; c) tt.climb( ) ; d) tt.jump( ) ;

34) 在JAVA语言中,下面变量命名合法的有()。(选择二项)

a) variable123 b) 123varible c) private

7

。 ) d) variable_123

35)给定一段JAVA代码如下:要打印出list中存储的内容,以下语句正确的是( )。(选择二项)

ArrayList list = new ArrayList( ) ; list.add(“a”) ; list.add(“b”) ;

Iterator it = list.iterator( ) ; a) while(it.hasNext( ) )

system.out.println(it.next( ) ) ; b) for(int i=0; i

system.out.println(list.get(i)) ; c) while(list.hasNext( ) )

system.out.println(list.next( ) ) ; d) for(int i=0; i

system.out.println(it(i)) ;

36) 下列Java Swing 组件,() 是容器组件。(选择二项)

a) JFrame b) JButton c) JTextArea d) JPanel

37) 给定某java 程序的main 方法如下,该程序的运行结果是() (选择一项) 。

pubtic static void main ( String[] args) { boolean boo=true; if ( boo== false) {

System.out.println (\}else {

System.out.println (\}

a) a b) b c) c d) d

38)下列选项中,不属于Java语言的关键字的是() 。(选择一项)

a) import b) malloc c) extends d) new

39)在JAVA中,() 类提供定位本地文件系统,对文件或目录及其属性进行基本操作。(选择一项)

a) Filelnputstream b) FileReader c) Filewriter d) File

40)在JAVA中,() 关键字用来终止循环语句。(选择一项)

a) return b) continue c) break

8