java笔试题1

上传人:第*** 文档编号:34053192 上传时间:2018-02-20 格式:DOC 页数:14 大小:39.50KB
返回 下载 相关 举报
java笔试题1_第1页
第1页 / 共14页
java笔试题1_第2页
第2页 / 共14页
java笔试题1_第3页
第3页 / 共14页
java笔试题1_第4页
第4页 / 共14页
java笔试题1_第5页
第5页 / 共14页
点击查看更多>>
资源描述

《java笔试题1》由会员分享,可在线阅读,更多相关《java笔试题1(14页珍藏版)》请在金锄头文库上搜索。

1、1.What will be the output when you compile and execute the following program.public class Baseprivate void test() System.out.println(6 + 6 + (Result);static public void main(String a) new Base().test();Select most appropriate answer.A 66(Result)B 12(Result)C Runtime Error.Incompatible type for +. Ca

2、nt convert an int to a string.D Compilation Error.Incompatible type for +. Cant add a string to an int.解答:B考点:字符串与基本数据的链接1.如果第一个是字符串那么后续都按字符串进行处理2.如果第一个到第 n个是基本数据,第 n+1个是字符串,那么前 n个数据都按加法计算,再与字符串链接2.What will be the output when you compile and execute the following program. The symbol means space.1:p

3、ublic class Base2:3: private void test() 4:5: String aStr = One ;6: String bStr = aStr;7: aStr.toUpperCase();8: aStr.trim();9: System.out.println( + aStr + , + bStr + );7: 8:9: static public void main(String a) 10: new Base().test();11: 12: Select most appropriate answer.A ONE, One B One ,OneC ONE,O

4、neD ONE,ONEE One , One 解答:E通过 String bStr = aStr;这句代码使 bStr 和 aStr 指向同一个地址空间。String 类是定长字符串,调用一个字符串的方法以后会形成一个新的字符串。3.Java 语言中,String 类的 indexOf()方法返回的类型是?A、Int16 B、Int32 C、int D、long解答:CindexOf 方法的声明为:public int indexOf(int ch)返回指定字符在字符串中第一次出现的索引,如果未出现该字符,则返回-14.执行下列代码后,哪个结论是正确的 String s=new String1

5、0;A s9 为 null;B s10 为 ;C s0 为 未定义D s.length 为 10解答:ADs 是引用类型,s 中的每一个成员都是引用类型,即 String 类型,String 类型默认的值为 null,s 数组的长度为 10。5. Given:public class Test public static void main(String args) String str = NULL;System.out.println(str);What is the result?A. NULLB. Compilation fails.C. The code runs with no o

6、utput.D. An exception is thrown at runtime.解答:Bnull 应该小写6、Given:public class Test public static void main (String args) class Foo public int i = 3;Object o = (Object) new Foo();Foo foo = (Foo)o;System.out.println(foo.i);What is the result?A. Compilation will fail.B. Compilation will succeed and the

7、program will print “3”C. Compilation will succeed but the program will throw a ClassCastException at line 6.D. Compilation will succeed but the program will throw a ClassCastException at line 7.解答:B考点:局部内部类的使用局部内部类定义在方法中,作用域相当于局部变量的作用域7、 Given:public class Test public static void main (String args)

8、String foo = “blue”;String bar = foo;foo = “green”;System.out.println(bar);What is the result?A. An exception is thrown.B. The code will not compile.C. The program prints “null”D. The program prints “blue”E. The program prints “green”解答:D采用 String foo = “blue”定义方式定义的字符串放在字符串池中,通过 String bar = foo;他们

9、指向了同一地址空间,就是同一个池子,当执行 foo = “green”; foo 指向新的地址空间。8.下面哪个是正确的?( )A. String temp = new String a b c;B. String temp = a b c;C. String temp = a, b, c;D. String temp = a, b, c;解答:DA.String temp = new String a, b, c;B. String temp = a,b,c;9.关于 java.lang.String 类,以下描述正确的一项是( )A. String 类是 final 类故不可以继承;B.

10、String 类是 final 类故可以继承;C. String 类不是 final 类故不可以继承;D. String 类不是 final 类故可以继承; 解答:AString 类是 final 的,在 java 中 final 修饰类的不能被继承10.从下面四段(A,B,C,D)代码中选择出正确的代码段()Aabstract class Name private String name;public abstract boolean isStupidName(String name) B public class Something void doSomething () private

11、String s = ;int l = s.length();C public class Something public static void main(String args) Other o = new Other();new Something().addOne(o);public void addOne(final Other o) o.i+;class Other public int i;Dpublic class Something public int addOne(final int x) return +x; 解答:CA.抽象方法不能有方法体B方法中定义的是局部变量,

12、不能用类成员变量修饰符 privateDfinal 修饰为常量,常量的值不能被改变11 String s = “Example”;合法的代码由哪些?A)s=3 B)s3= “X” C)int i = s.length() D)s = s +10解答:CDA. 移位运算,要是整数类型。B s 不是数组C String 类取长度的方法为: length()D. 字符串相加12.已知表达式 int m = 0,1,2,3,4,5,6;下面哪个表达式的值与数组下标量总数相等?( )A .m.length()B.m.lengthC.m.length()+1D.m.length+1解答:B解答:数组下标是

13、从零开始的,但是数据下标的总量和数据长度相同。只有 String 类型才有 length()方法,其他的类型都是 length 属性13.给出如下代码: ) (class Testprivate int m;public static void fun() /some code如何使成员变量 m 被函数 fun()直接访问?()A.将 private int m 改为 protected int mB.将 private int m 改为 public int mC.将 private int m 改为 static int mD.将 private int m 改为 int m解答:C静态的

14、方法中可以直接调用静态数据成员14下述代码的执行结果是class Super public int getLength() return 4;public class Sub extends Super public long getLength() return 5;public static void main (Stringargs) Super sooper = new Super ();Super sub = new Sub();System.out.printIn(sooper.getLength()+ “,” + sub.getLength() ;A. 4, 4B. 4, 5C.

15、 5, 4D. 5, 5E. 代码不能被编译解答:E方法重写返回值类型与父类的一致15. 指出下列程序运行的结果public class ExampleString str=new String(good);charch=a,b,c; public static void main(String args)Example ex=new Example();ex.change(ex.str,ex.ch);System.out.print(ex.str+ and );System.out.print(ex.ch);public void change(String str,char ch)str=test ok;ch0=g;A good and abcB good and gbcC test ok and abcD test ok and gbc解答:B数组和字符串都是引用类型

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 解决方案

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号