java面向对象考试题

上传人:新** 文档编号:508399747 上传时间:2023-11-06 格式:DOC 页数:14 大小:61KB
返回 下载 相关 举报
java面向对象考试题_第1页
第1页 / 共14页
java面向对象考试题_第2页
第2页 / 共14页
java面向对象考试题_第3页
第3页 / 共14页
java面向对象考试题_第4页
第4页 / 共14页
java面向对象考试题_第5页
第5页 / 共14页
点击查看更多>>
资源描述

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

1、真诚为您提供优质参考资料,若有不当之处,请指正。第一题:public static void main (String args)String fileNames = abc.txt, bcd.exe, cde.exe,def.dat,efg.exe ; for (String fileName : fileNames) if (fileName.endsWith(.exe) System.out.print(fileName.substring(0, fileName.lastIndexOf(.exe)+ );fileName.endsWith(.exe)判断是否已.exe结尾substri

2、ng(0,4)截取0-3的字符串,不包含4lastIndexOf(.exe)获取.exe最后一次出现的位置答案:bcd cde efg第二题:public static void go(Long n) System.out.println(Long); public static void go(Short n) System.out.println(Short); public static void go(int n) System.out.println(int); public static void main(String args) short y = 6; long z = 7;

3、 go(y); go(z); 虽然y是short型的,但是编译器把它转换为int型答案:int Long第三题:public static void main(String args)String test = Test A. Test B. Test C.;String regex = .s*; String result = test.split(regex); for(String s : result) System.out.print(s + ); s 空白字符 *表示0个或任意多个 text.split(.)按.拆分答案: Test A Test B Test C 第四题:publ

4、ic class AA private Long userId; private String nickName; public Long getUserId() return userId;public void setUserId(Long userId) this.userId = userId;public String getNickName() return nickName;public void setNickName(String nickName) this.nickName = nickName;public static void main(String args)AA

5、 m1=new AA(); m1.setUserId(new Long(100001); m1.setNickName(mick); AA m2=new AA(); m2.setUserId(new Long(100001); m2.setNickName(mick); System.out.println(m1=m2); System.out.println(m1.equals(m2); equals方法返回值也是return m1=m2答案:false false第五题运行下列代码,输出为false的是:()。A.String st1 = abc;System.out.println(ab

6、c = st1);B.String st2 = abcSystem.out.println(st2.equals(newString(abc);C.Integer i = 100; System.out.println(100 = i);D.ArrayList list = new ArrayList();System.out.println(list.contains(null);答案:D第六题public interface Cookie Cookie cookie=new Cart (小面包,盼盼); public class Cart implements Cookie private

7、 String name; private String production;public Cart(String name,String production) this.name=name; this.production=production; public void smell()cookie =new Cart(蛋黄派,达利园); final 要求属性不可更改cookie =new Cart(蛋黄派,达利园); 这个修改了 cookie的地址,所以报错第七题(多选)请看下列代码: public abstract class Shape int x;int y; public abs

8、tract void draw(); public void setAnchor(int x, int y) this.x = x; this.y = y;下列选项中能正确使用Shape类的是:A.public class Circle implements Shape private int radius; B.public abstract class Circle extends Shape private int radius; C.public class Circle extends Shape private int radius; public void draw(); D.p

9、ublic class Circle extends Shape private int radius;public void draw() 抽象类不可以实例化,如果一个类继承了抽象类,必须重新其抽象方法答案:BD第八题(多选)请看下列代码:package com.tarena;public class Geodetics public static final double DIAMETER = 12756.32;访问静态常量DIAMETER的方式正确的是:A.import com.tarena.Geodetics;public class TerraCarta public double

10、halfway()return Geodetics.DIAMETER/2.0;B.import com.tarena.Geodetics;public class TerraCarta public double halfway()return DIAMETER/2.0;C.import com.tarena;public class TerraCarta public double halfway()return Geodetics.DIAMETER/2.0;D.import com.tarena.*;public class TerraCarta public double halfway

11、()return Geodetics.DIAMETER/2.0;答案:AD第九题(多选)在Java语言中,下列说法正确的是()。A.一个接口可以继承多个接口B.一个类可以继承多个类C.一个类可以实现多个接口D.一个类可以有多个子类答案:ACD第十题(多选)在处,填入下列代码编译正确的是:public void foo(int x) A.foreach(int z : x) System.out.println(z);B.for(int z : x) System.out.println(z);C.while( x.hasNext() System.out.println( x.next();D

12、.for( int i=0; i x.length; i+ ) System.out.println(xi);答案:BD第十一题(多选)查看如下代码:class A protected int method (int a, int b) return 0; 下列选项中,可以在 A 的子类中使用的是()。A.public int method (int a, int b) return 0; B.private int method(int a, int b) return 0; C.private int method(int a, long b) return 0; D.public sho

13、rt method(int a, int b) return 0; A:重写A类中的方法 C:重载A类中的方法答案:AC第十二题(多选)在Java语言中,下列说法正确的是:()。A.StringBuffer和StringBuilder的区别在于:StringBuffer是线程安全的而StringBuilder不是。B.String是不可变对象,而StringBuffer中封装的字符串数据是可以动态改变的C.判断两个StringBuilder对象的字符序列是否相同,可以调用其equlas方法进行比较。D.String的重写了equals方法,重写的逻辑是:字符序列相同的String对象equals方法返回true。答案:ABD第十三题(多选)题目代码的功能为:输出每个字符在一个字符串中出现的次数(不区分大小写)。String str = ewrwqFrewqfsadfdsfdsfs; str=str.toLowerCase(); int max_length = 0;while (str.length()

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

当前位置:首页 > 高等教育 > 其它相关文档

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