java笔试题.doc

上传人:s****u 文档编号:12766808 上传时间:2020-05-23 格式:DOC 页数:14 大小:39.50KB
返回 下载 相关 举报
java笔试题.doc_第1页
第1页 / 共14页
java笔试题.doc_第2页
第2页 / 共14页
java笔试题.doc_第3页
第3页 / 共14页
点击查看更多>>
资源描述
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.0D、 编译错误解答:C三目运算符中:第二个表达式和第三个表达式中如果都为基本数据类型,整个表达式的运算结果由容量高的决定。99.9 是 double 类型 而 9 是 int 类型,double 容量高。20.以下关于面向对象概念的描述中,不正确的一项是() 。(选择 1 项)A.在现实生活中,对象是指客观世界的实体B.程序中的对象就是现实生活中的对象C.在程序中,对象是通过一种抽象数据类型来描述的,这种抽象数据类型称为类(class)D.在程序中,对象是一组变量和相关方法的集合解答:B
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 图纸专区 > 考试试卷


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!