java面向对象考试,java面向对象考试题

41528d3028836879cd698677c3999917.gifjava面向对象考试题

第一题: public static void main (String[] args){ String[] fileNames = { “abc.txt“, “bcd.“, “cde.“,“def.dat“,“efg.“ }; for (String fileName : fileNames) { if (fileName.endsWith(“.“)) { System.out.print(fileName.substring(0, fileName.lastIndexOf(“.“))+“ “); } } } fileName.endsWith(“.“)判断是否已“.“结尾 substring(0,4)截取0-3的字符串,不包含4 lastIndexOf(“.“)获取“.“最后一次出现的位置 答案: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; 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 第四题: public 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 m1=new AA(); m1.setUserId(new Long()); m1.setNickName(“mick“); AA m2=new AA(); m2.setUserId(new Long()); 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(“abc“ == st1); B.String st2 = “abc“System.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 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 abstract 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.public class Circle extends Shape { private int radius

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值