/ **
* 10道题系列会持续更新,每日的10道题都是我做过的,做错或者觉得需要复习的有价值的
*请关注我,每日和我一同进步,有更好的建议或有问题的请在评论区提出或私信我
* /
1.执行以下程序后的输出结果是()
public class Test {
public static void main(String[] args) {
StringBuffer a = new StringBuffer("A");
StringBuffer b = new StringBuffer("B");
operator(a, b);
System.out.println(a + "," + b);
}
public static void operator(StringBuffer x, StringBuffer y) {
x.append(y); y = x;
}
}
A.A,A
B.A,B
C.B,B
D.AB,B
2.以下代码在编译和运行过程中会出现什么情况
public class TestDemo{
private int count;
public static void main(String[] args) {
TestDemo test=new TestDemo(88);
System.out.println(test.count);
}
TestDemo(int a) {
count=a;
}
}
A.编译运行通过,输出结果是88
B.编译时错误,count变量定义的是私有变量
C.编译时错误,System.out.println方法被调用时test没有被初始化
D.编译和执行时没有输出结果
3.在java中,下列标识符不合法的有( )
A.new
B.$Usdollars
C.1234
D.car.taxi
4.java中,StringBuilder和StringBuffer的区别,下面说法错误的是?
A.StringBuffer是线程安全的
B.StringBuilder是非线程安全的
C.StringBuffer对 String 类型进行改变的时候其实都等同于生成了一个新的 String 对象,然后将指针指向新的 String 对象。
D.效率比较String<StringBuffer<StringBuilder,但是在 String S1 = “This is only a” + “ simple” + “ test”时,String效率最高。
5.Given the following code:
import EnclosingOne.InsideOne
1.class Enclosingone
2.{
3. public class InsideOne {}
4.
5.}
6.public class inertest
7.{
8. public static void main(string[]args)
9. {
10. EnclosingOne eo = new EnclosingOne();
11. //insert code here
12. }
13.
14.}
Which statement at line 11 constructs an instance of the inner class?
A.InsideOne ei=eo.new InsideOne();
B.eo.InsideOne ei=eo.new InsideOne();
C.InsideOne ei=EnclosingOne.new InsideOne();
D.EnclosingOne.InsideOne ei=eo.new InsideOne();
6.下列程序的输出结果是什么?
public class Test1{
public static void main(String args[]){
String a="1234";
String b="1234";
String c = new String("1234");
System.out.println(a==b);
System.out.println(a==c);
System.out.println(a.equals(c));
}
}
A. true
false
true
B true
true
false
C true
false
false
D true
true
true
7.下列代码执行结果为()
public static void main(String args[])throws InterruptedException{
Thread t=new Thread(new Runnable() {
public void run() {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
System.out.print("2");
}
});
t.start();
t.join();
System.out.print("1");
}
A.21
B.12
C.可能为12,也可能为21
D.以上答案都不对
8.java语言的下面几种数组复制方法中,哪个效率最高?
A.for 循环逐一复制
B.System.arraycopy
C.Array.copyOf
D.使用clone方法
9.以下哪项不属于java类加载过程?
A.生成java.lang.Class对象
B.int类型对象成员变量赋予默认值
C.执行static块代码
D.类方法解析
10.JAVA中,下列语句哪一个正确()
A.class中的constructor不可省略
B.constructor必须与class同名,但方法不能与class同名
C.constructor在一个对象被new时执行
D.一个class只能定义一个constructor