第四部分 数组、字符串、向量和哈希表
1、下面关于向量的描述正确的是(ABCD)
A、向量在功能上与数组类似,只是其元素个数可以改变,并且向量元素必须是引用类型;
B、他们都有成员域实际元素个数size和容量capacty; C、数组的存储大小不能改变,而向量的存储能力可以改变; D、数组的容量成员为length,而向量的容量为capacity。 2、下面正确声明一个一维数组的是(A B)。 A、String [] a B、String a[] C、char a[][] D、String a[10]
3、执行完以下代码int [ ] x = new int[10];后,以下哪项说明是正确的(A) A.x[9]为0 B.x[9]未定义 C.x[10]为0 D.x[0]为空 4、关于以下程序段,正确的说法是(C)
1. String s1=“a”+“b”;
2. String s2=new String(s1); 3. if(s1= =s2)
4. = is succeeded”); 5. if (s2))
6. is succeeded”);
A.行4与行6都将执行 B.行4执行,行6不执行 C.行6执行,行4不执行 C.行4、行6都不执行
5、有整型数组:int[] x={2,33,88,5,10};, 则调用方法 (x) 后,数组x中的元素值依次是(B)。
A、 B、 C、 D、
6、下列数组初始化形式正确的是(A)。 A. int t1[][]={{1,2},{3,4},{5,6}}; B. int t2[][]={1,2,3,4,5,6}; C. int t3[3][2]={1,2,3,4,5,6}; D. int t4[][]; t4={1,2,3,4,5,6}; 7、关于以下程序段,正确的说法是(C)
1. String s1=”abc”+”def”; 2. String s2=new String(s1); 3. if(s1= =s2)
4. = succeeded”); 5. if (s2))
6. succeeded”);
A、行4与行6都将执行 B、行4执行,行6不执行 C、行6执行,行4不执行 C、行4、行6都不执行
8、下面的程序段执行后输出的结果是(C)。
StringBuffer buf=new StringBuffer(\"China2008\"); (5,\"@\"); ( )); A、China2008@ B、@China2008 C、China@2008 D、China#2008
9、关于以下application的说明,正确的是(C)
1. class StaticStuff 2. {
3. static int x=10; 4. static { x+=5;}
5. public static void main(String args[ ])
6. {
7. + x); 8. }
9. static { x/=3;} 10. }
A、4行与9行不能通过编译,因为缺少方法名和返回类型 B、9行不能通过编译,因为只能有一个静态初始化器 C、编译通过,执行结果为:x=5 D、编译通过,执行结果为:x=3
10、String或StringBuffer类的对象在调用以下哪个方法时其自身会发生更改(BCD) A) String类的charAt()方法。
B) String类的toUpperCase()方法。 C) String类的replace()方法。
D) StringBuffer类的reverse ()方法。 E) StringBuffer类的length ()方法。 11、阅读以下代码:
import .*; import .*;
public class foo{
public static void main (String[] args){
String s; \"s=\" + s); } }
输出结果应该是:(C)
A.代码得到编译,并输出“s=” B.代码得到编译,并输出“s=null”
C.由于String s没有初始化,代码不能编译通过
D.代码得到编译,但捕获到 NullPointException异常
12、以下关于abstract的说法,正确的是(D)。 A、abstract只能修饰类 B、abstract只能修饰方法
C、abstract类中必须有abstract方法
D、abstract方法所在的类必须用abstract修饰 13、写出以下程序的运行结果。
public class ChangeStrDemo {
public static void changestr(String str){ str=\"welcome\"; }
public static void main(String[] args) { String str=\"1234\"; changestr(str); } }
运行程序的显示结果为:1234 14、写出以下程序的运行结果。
class First{ public First(){ aMethod(); } public void aMethod(){ First class”);} }
public class Second extends First{ public void aMethod(){ Second class”);}
public static void main(String[ ] args){ new Second( ); } }
运行程序的显示结果为:in Second class 15、写出以下程序的运行结果。 public class FooDemo{
static boolean foo(char c) {
return true; }
public static void main(String[] args ) { int i =0;
for ( foo(’a’); foo(’b’)&&(i<2); foo(’c’)){ i++ ;
foo(’d’); } }
}
运行程序的显示结果为:abdcbdcb
16、关于以下程序代码的说明正确的是(D)
1.class HasStatic{
2. private static int x=100;
3. public static void main(String args[ ]){ 4. HasStatic hs1=new HasStatic( ); 5. ++;
6. HasStatic hs2=new HasStatic( ); 7. ++;
8. hs1=new HasStatic( ); 9. ++;
10. -;
11. } 13. }
A、 5行不能通过编译,因为引用了私有静态变量 B、 10行不能通过编译,因为x是私有静态变量 C、 程序通过编译,输出结果为:x=103 D、 程序通过编译,输出结果为:x=102 17、写出以下程序的运行结果。//结果为:
class OverloadDemo{
void testOverload( int i ){ }
void testOverload(String s){ }
public static void main(String args[ ]){ OverloadDemo a=new OverloadDemo ( ); char ch=’x’; (ch); } }
运行程序的显示结果为:int 精心搜集整理,只为你的需要
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- igat.cn 版权所有 赣ICP备2024042791号-1
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务