java笔试题1.doc_第1页
java笔试题1.doc_第2页
java笔试题1.doc_第3页
java笔试题1.doc_第4页
java笔试题1.doc_第5页
免费预览已结束,剩余10页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

资料收集于网络,如有侵权请联系网站删除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 +. Cant 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:public 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,OneD 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 String10;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 output.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 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) 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; 他们指向了同一地址空间,就是同一个池子,当执行 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. 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) Bpublic class Something void doSomething () private String s = ;int l = s.length();Cpublic 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方法中定义的是局部变量,不能用类成员变量修饰符 privateDfinal 修饰为常量,常量的值不能被改变11 String s = “Example”;合法的代码由哪些?A)s=3 B)s3= “X” C)int i = s.length() D)s = s +10解答:CDA. 移位运算,要是整数类型。Bs 不是数组CString 类取长度的方法为: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解答:数组下标是从零开始的,但是数据下标的总量和数据长度相同。只有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下述代码的执行结果是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, 4 B. 4, 5 C. 5, 4 D. 5, 5 E. 代码不能被编译解答:E方法重写返回值类型与父类的一致 15. 指出下列程序运行的结果 public class Example String 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数组和字符串都是引用类型。Java中参数传递是基于值的传递:基本数据:传递的是实际的值引用类型:传递的是地址值16. String s=new String(“hello”); String t =new String(“hello”); char c =h,e,l,l,o; 下列哪些表达式返回 true ?As.equals(t);Bt.equals(c);Cs= =t ;Dt.equals (new String(“hello”);Et= = c;解答:AD String 类的 equals 方法已经覆盖了 Object 类的 equals 方法,比较的是两个字符串的内容是否相等,双等号比较的是两个对象的内存地址是否相等17. 类 Teacher 和 Student 是类 Person 的子类;Teacher t;Student s;/ t and s are all non-null.if (t instanceof Person ) s=(Student)t; 最后一条语句的结果是:A将构造一个 Student 对象;B表达式是合法的;C表达式是错误的;D编译时正确, 但运行时错误。解答:Dinstanceof 是 Java 的一个二元操作符,它的作用是测试它左边的对象是否是它右边的类的实例,返回 boolean 类型的数据。Teahcer 和 Student 之间没有继承关系不能做强制类型转换。18.下面关于变量及其范围的陈述哪些是不正确的( ):A实例变量是类的成员变量B实例变量用关键字 static 声明C在方法中定义的局部变量在该方法被执行时创建D局部变量在使用前必须被初始化解答:BCB.由 static 修饰的变量称为类变量或是静态变量C.方法加载的时候创建局部变量公司成功地创造了这样一种气氛:商店和顾客不再是单纯的买卖关系,营业员只是起着参谋的作用,顾客成为商品或者说是作品的作参与者,营业员和顾客互相交流切磋,成为一个共同的创作体19.编译运行以下程序后,关于输出结果的说明正确的是 ( ): public class Conditional尽管售价不菲,但仍没挡住喜欢它的人来来往往。这里有营业员们向顾客们示范着制作各种风格迥异的饰品,许多顾客也是学得不亦乐乎。在现场,有上班族在里面精挑细选成品,有细心的小女孩在仔细盘算着用料和价钱,准备自己制作的原料。可以想见,用本来稀奇的原料,加上别具匠心的制作,每一款成品都必是独一无二的。而这也许正是自己制造所能带来最大的快乐吧。 public static void main(String args )创新是时下非常流行的一个词,确实创新能力是相当重要的特别是对我们这种经营时尚饰品的小店,更应该勇于创新。在这方面我们是很欠缺的,故我们在小店经营的时候会遇到些困难,不过我们会克服困难,努力创新,把我们的小店经营好。 int x=4; System.out.println(“value is “+ (x4) ? 99.9 :9);手工艺制品是我国一种传统文化的象征,它品种多样,方式新颖,制作简单,深受广大学生朋友的喜欢。当今大学生的消费行为表现在追求新颖,追求时尚。追求个性,表现自我的消费趋向:购买行为有较强的感情色彩,比起男生热衷于的网络游戏,极限运动,手工艺制品更得女生的喜欢。A、 输出结果为:value is 99.99B、 输出结果为:value is 9C、 输出结果为:value is 9.0综上所述,DIY手工艺品市场致所以受到认可、欢迎的原因就在于此。我们认为:这一市场的消费需求的容量是极大的,具有很大的发展潜力,我们的这一创业项目具有成功的前提。D、 编译错误解答:C人民广场地铁站有一家名为“漂亮女生”的饰品店,小店新开,10平方米不到的店堂里挤满了穿着时尚的女孩子。不几日,在北京东路、淮海东路也发现了“漂亮女生”的踪影,生意也十分火爆。现在上海卖饰品的小店不计其数,大家都在叫生意难做,而“漂亮女生”却用自己独特的经营方式和魅力吸引了大批的女生。三目运算符中:第二个表达式和第

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论