文档介绍:Java基础试题及其答案
Java基础试题及其答案
Java基础试题及其答案
Java试题
一 单项选择
1) 在Java中,,要让包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;
(a%2==1) ?(a+1) /2:a/2) ;
}
} (选择一项)
a)1
Java基础试题及其答案
Java基础试题及其答案
Java基础试题及其答案
b)2
c)2。5
d)3
6) 以下Java语句中,String str = “123456789";str =str。subString(1,3);执行后str中的值为。(选择一项)
a) “23”
b) “123"
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 () ;//第四行
}
} (选择一项)
第一行
第二行
第三行
第四行
8) 给定如下java代码,编译运行时,结果是()。 (选择一项)
public class Test{
public static void main (String args[]) {
for (int i=0;i〈3; i++) {
System.(i) ;
}
(i) ;
}
}
a) 编译时报错
b) 正确运行,输出012
c) 正确运行,输出123
d) 正确运行,输出0123
Java基础试题及其答案
Java基础试题及其答案
Java基础试题及其答案
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 impleme