Java选择题及其答案 下载本文

内容发布更新时间 : 2024/5/10 21:43:11星期一 下面是文章的全部内容请认真阅读。

Java试题—选择题、简答题、设计题

说明:没上过的内容可以跳过 一、选择题(20题,30分)

1) java程序中,main方法的格式正确的是()。 a)static void main(String[] args) b)public void main(String[] args) c)public static void main(String[]s)

d)public static void main(String[] args)

2) 在Java中,在包com.db下定义一个类,要让包com.util下的所有类都可以访问这个类,

这个类必须定义为()。 a)protected b)private c)public d)friendly

3) 在Java中,下列()语句不能通过编译。 a) String s= “join”+ “was”+ “here”; b) String s= “join”+3; c) int a= 3+5 d) float f=5+5.5;

4) 在Java中下列()方法可以把JFrame的布局管理器设为FlowLayout类型 a)jFrame.setLayout(new FlowLayout() ); b) jFrame.addLayout(new FlowLayout() )

c)jFrame.setFlowLayout() d)jFrame.addFlowLayout()

5)给定java代码如下,运行时,会产生()类型的异常。

String s=null; s.concat(“abc”); a)ArithmeticException b)NullPointerException c)IOException d)EOFException

6) 以下Java语句中,String str = “123456789”;str =str.subString(1,3);执行后str中的值为。

a) “23” b) “123” c) “12” d) “234”

7)给定某java程序的main方法,如下:

public static void main (String[]arg){ System.out.print( “Hello”+args[1]) ; }

从命令行传参:people world nation,该程序的运行结果是()。

a) Hello people b) Hello world

1

c) Hello people world nation d) 运行时出现异常 8) 给定Java代码,如下: abstract class Shape{

abstract void draw() ; }

要创建Shape类的子类Circle,以下代码正确的是() a) class Circle extends Shape{ int draw() {} }

b) abstract class Circle extends Shape{ void draw() }

c) class Circle extends Shape{ void draw() ; }

d) class Circle extends Shape{ void draw() {} }

9) 给定如下java代码,编译运行时,结果是()。 (选择一项)

public class Test{

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

System.out.print(i) ;

}

}

a) 编译时报错

b) 正确运行,输出012 c) 正确运行,输出123 d) 正确运行,输出0123

10 给定一个Java程序的方法结构如下;以下方法体实现语句正确的是( public Integer change( int i) { }

a) Integer int =new Integer( i) ;

return int;

b) Integer t = new Integer

return t;

c) return new Integer( i) ; d) return i;

11) 在java中,在尝试对null 对象操作时,会产生( )类型的异常。 a) ArithmeticException b) NullPointerException c) IOException

2

。 )

d) EOFException 6)

12) Java语言中,String str=”123456789”,System.out.println(str.indexOf(“5”)),输出结果为()。 a) 6 b) 5 c) 4 d) -1

13) 在java中,已定义两个接口B和C,要定义一个实现这两个接口的类,以下语句正确

的是( ) 。 a) interface A extends B,C b) interface A implements B,C c) class A implements B,C d) class A implements B,implements C 14) 给定某java程序的main方法,如下;

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

a) 0 b) 1

c) 编译错误

d) 运行时出现异常

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

a) File

b) FileOutputStrean c) PrintWriter d) Dir

16) 在java 中,下列( ) 类不能派生出子类.

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

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

17) 在java 中,以下( )命令能够将java源文件编译为类文件 a) java b) javaw c) javac d) jar

18) 在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))

3

)判断语句。(选择(选择一项) 19) 给定JAVA代码,如下:编译运行,结果是( )。(选择一项)

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

a) 编译错误

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

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

a) variable-123 b) 123varible c) private

d) variable_123

21)给定一段JAVA代码如下:要打印出list中存储的内容,以下语句正确的是(ArrayList list = new ArrayList( ) ; list.add(“a”) ; list.add(“b”) ;

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

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)) ;

22) 下列Java Swing 组件,() 是容器组件。

a) JFrame b) JButton c) JTextArea d)

23) 给定某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

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

a) import

4

。 )

b) malloc c) extends d) new

25)在JAVA中,() 关键字用来终止循环语句。

a) return b) continue c) break d) exit

26) 给定Java代码如下,关于super的用法,以下描述正确的是() 。

class C extends B { public C() {

super() ; } } a) 用来调用类B 中定义的super() 方法 b) 用来调用类C 中定义的super() 方法 c) 用来调用类B 的无参构造方法

d) 用来调用类B 中第一个出现的构造方法 27) 给定java代码如下,编译运行,结果是() 。

public static void main (String[] args) { int i;

System.out.println (“i=“+i) ; }

a) 编泽错误

b) 运行时出现例外

c) 正常运行,输出i=-1 d) 正常运行,输出i=0

28) 研究下面的Java 代码,当x=2 时,运行结果是() 。

switch ( x) {

case1: System.out.println(1) ; case2:

case3: System.out.println(3) ; Case4: System.out.println(4) ; }

a) 没有输出任何结果 b) 输出结果为3

c) 输出结果是3 和4 d) 输出结果是l 、3 和4 29) 类java.util.HashMap 实现了()接口。

a) Collection b) Set c) Map

d) List 30) 在java中,使用关键字来定义一个接口。 class b) interface

c) extends d) implements 31) 在java中,()接口位于集合框架的顶层(选择一项)

5

a)