Java试题
一 单项选择
1) 在Java中,在包com.db下定义一个类,要让包com.util下的所有类都可以访问这个类,
这个类必须定义为()。 () a)protected b)private c)public d)friendly
2) 在Java中,下列()语句不能通过编译。 (选择一项) a) String s= “join”+ “was”+ “here”; b) String s= “join”+3; c) int a= 3+5 d) float f=5+5.5;
3)给定java代码如下,运行时,会产生()类型的异常。(选择一项)
String s=null; s.concat(“abc”); a)ArithmeticException b)NullPointerException c)IOException d)EOFException 4) 在java中,()对象可以使用键/值的形式保存数据。 (选择一项) a)ArrayList b) HashSet c) HashMap d) LinkedList
5) 给定如下java代码,编译运行之后,将会输出()。 public class Test{
public staticvoid main(String args[]){ int a=5;
System.out.println(a%2==1) ?(a+1) /2:a/2) ; }
} (选择一项) a)1 b)2 c)2.5 d)3 6) 以下Java语句中,String str = “123456789”;str =str.subString(1,3);执行后str中的值为。(选
择一项) a) “23” b) “123”
1
c) “12” d) “234”
7) 给定如下java代码,编译时会在()出现错误。 class Parent{ }
class Child extends Parent{
public static void main(String args[]){ Parent p1=new Child() ;//第一行 Parent p2=new Parent () ;//第二行 Child c1=new Child() ;//第三行 Child c2=new Parent () ;//第四行 }
} (选择一项)
a) 第一行 b) 第二行 c) 第三行 d) 第四行
8) 给定如下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
9) Java语言中,String str=”123456789”,System.out.println(str.indexOf(“5”)),输出结果为()。(选择一项) a) 6 b) 5 c) 4 d) -1
10) 在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 11) 下列说法中错误的一项是()
a) 线程就是程序
2
b) 线程是一个程序的单个执行流
c) 多线程是指一个程序的多个执行流 d) 多线程用于实现并发
12)给定JAVA代码,如下:
Class Parent{
public void count() {
System.out.println(10%3) ; } }
public class Test extends Parent{ public void count() {
System.out.println(10/3) ; }
public static void main(String args[]) { Parent p = new Test() ; p.count() ; } }
运行编译后,输出结果是( )。(选择一项) a) 1 b) 1.0 c) 3
d) 3.3333333333333335
13) 给定某java程序的main方法,如下;(选择一项)
public static void main(String [ ]args) { int i = 0; System.out.println(i++) ; }
a) 0 b) 1
c) 编译错误
d) 运行时出现异常
14)给定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) 运行时出现异常
3
15) 下列哪个一个操作不能使线程从等待阻塞状态进入对象阻塞状态(D) a) 等待阴塞状态下的线程被notify()唤
b) 等待阻塞状态下的纯种被interrput()中断 c) 等待时间到
d) 等待阻塞状态下的线程调用wait()方法
16)在JAVA中,要创建一个新目录,要使用( )类的实例。(选择一项)
a) File
b) FileOutputStrean c) PrintWriter d) Dir
17) 在java 中,下列( ) 类不能派生出子类. (选择一项)
a) public class MyClass{ } b) class MyClass{ }
c) abstract class MyClass{ } d) final class MyClass { }
18) 在java 中,以下( )命令能够将java源文件编译为类文件 (选择一项)
a) java b) javaw c) javac d) jar
19) 在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))
20) 给定JAVA代码,如下:编译运行,结果是( )。(选择一项)
public static void main(string[] args) { String s; System.out.println(“s=”+s) ; }
a) 编译错误
b) 编译通过,但出现运行是错误 c) 正常运行,输出s=null d) 正常运行,输出s=
21) 给定一个java程序的main方法的代码片段如下:假如d 目录下不存在abc.txt文件,现运行该程序,下面的结果正确的是( )。 ( 选择一项)
try {
PrintWriter out=new PrintWriter(new FileOutputStream(“d:/abc.txt”)) ; String name=”chen”; out.print(name) ;
4
out.close( ) ; }
catch(Execption e) {
System.out.println(“文件没有发现!“) ; }
a) 将在控制台上打印:“文件没有发现!” b) 正常运行,但没有生成文件abc.txt c) 运行后生成abc.txt ,但该文件中无内容 d) 运行后生成abc.txt,该文件内容为:chen
22) 下列哪个方法可以使线程从运行状态进入其他阻塞状态(A)
a) sleep b) wait c) yield d) start
23) 给定某java 程序的main 方法如下,该程序的运行结果是() (选择一项) 。
public 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 b) malloc c) extends d) new
25)在JAVA中,() 类提供定位本地文件系统,对文件或目录及其属性进行基本操作。(选择一项)
a) Filelnputstream b) FileReader c) Filewriter d) File
26)在JAVA中,() 关键字用来终止循环语句。(选择一项)
a) return b) continue c) break d) exit
27) 给定java 代码,如下,编译运行后,结果是0。(选择一项)
public class Test{ static String s;
public static void main(String args[]) {
char c=s.charAt(0) ; System.out.println(c) ; }} a) 编译错误
b) 运行期异常,异常类型为NullPointerException
5
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库Java基础试题及其答案汇总在线全文阅读。
相关推荐: