java面向对象考试题

第一题:

public static void main (String[] args){

String[] fileNames = { \ \ 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(\}

public static void go(Short n) { System.out.println(\}

public static void go(int n) { System.out.println(\}

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 = \ String regex = \

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(100001)); m1.setNickName(\ AA m2=new AA();

m2.setUserId(new Long(100001)); m2.setNickName(\

System.out.println(m1==m2);

System.out.println(m1.equals(m2)); }

equals方法返回值也是return m1==m2 答案:false false

第五题

运行下列代码,输出为false的是:()。

A.String st1 = \ B.Stringst2=

\ 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 {

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4