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”