JAVA选择题分析
7分析下面的Java程序段,编译运行后的输出结果是(D)。(选择一项)publicclassTest{publicvoidchangeString(StringBuffe...
7 分析下面的Java 程序段,编译运行后的输出结果是(D)。(选择一项)
public class Test {
public void changeString(StringBuffer sb) {
sb.append("stringbuffer2");
}
public static void main(String[] args) {
Test a = new Test();
StringBuffer sb = new StringBuffer("stringbuffer1");
a.changeString(sb);
System.out.println("sb = " + sb);
}
}
A) sb = stringbuffer2stringbuffer1 B) sb = stringbuffer1
C) sb = stringbuffer2 D) sb =stringbuffer1stringbuffer2
20 给定一个Java 程序的代码如下所示,则编译运行后,输出结果是(A)。(选择一项)
public class Test {
int count = 9;
public void count( ) {
System.out.println("count=" + count++);
}public static void main(String args[]) {
new Test( ).count( );
new Test( ).count( );
}
}
A) count=9 count=9 B) count=10 count=9
C) count=10 count=10 D) count=9 count=10
22 执行下列代码段后,变量x 的值是(A)。(选择一项)
x=9;
y=9;
x=(y<=x++)?1:0;
A) 1 B) 2 C) 0 D) 10
29 下面(AC)正确创建包含5 个""字符串的数组。(选择两项)
A) String[ ] a = new String[5];for(int i=0 ; i< 5; i++ ){a[i]="";}
B) String a[ ] = new String[ ] ;a ={"","","","",""};
C) String[ ] a ={"","","","",""}
;D) String a[ ] = new String[5]{"","","","",""};
30 阅读下面代码片段,输出结果是(D)。(选择一项)
StringBuffer sb = new StringBuffer("Hello");
String t = " MY";
t = t + " FRIEND";sb.append(t);
System.out.println(sb.toString().toLowerCase());
A) my friend hello B) Hello MY FRIEND
C) MY FRIEND Hello D) hello myfriend
31 下面代码片段创建(B )个对象。(选择一项)
int a = 10;
String b = "abc";
String c = new String("abc");
MyTest test = new MyTest();
A) 4 B) 3 C) 2 D) 1 展开
public class Test {
public void changeString(StringBuffer sb) {
sb.append("stringbuffer2");
}
public static void main(String[] args) {
Test a = new Test();
StringBuffer sb = new StringBuffer("stringbuffer1");
a.changeString(sb);
System.out.println("sb = " + sb);
}
}
A) sb = stringbuffer2stringbuffer1 B) sb = stringbuffer1
C) sb = stringbuffer2 D) sb =stringbuffer1stringbuffer2
20 给定一个Java 程序的代码如下所示,则编译运行后,输出结果是(A)。(选择一项)
public class Test {
int count = 9;
public void count( ) {
System.out.println("count=" + count++);
}public static void main(String args[]) {
new Test( ).count( );
new Test( ).count( );
}
}
A) count=9 count=9 B) count=10 count=9
C) count=10 count=10 D) count=9 count=10
22 执行下列代码段后,变量x 的值是(A)。(选择一项)
x=9;
y=9;
x=(y<=x++)?1:0;
A) 1 B) 2 C) 0 D) 10
29 下面(AC)正确创建包含5 个""字符串的数组。(选择两项)
A) String[ ] a = new String[5];for(int i=0 ; i< 5; i++ ){a[i]="";}
B) String a[ ] = new String[ ] ;a ={"","","","",""};
C) String[ ] a ={"","","","",""}
;D) String a[ ] = new String[5]{"","","","",""};
30 阅读下面代码片段,输出结果是(D)。(选择一项)
StringBuffer sb = new StringBuffer("Hello");
String t = " MY";
t = t + " FRIEND";sb.append(t);
System.out.println(sb.toString().toLowerCase());
A) my friend hello B) Hello MY FRIEND
C) MY FRIEND Hello D) hello myfriend
31 下面代码片段创建(B )个对象。(选择一项)
int a = 10;
String b = "abc";
String c = new String("abc");
MyTest test = new MyTest();
A) 4 B) 3 C) 2 D) 1 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询