A.Thecodewillcompilewithoutchanges.
B.ThecodewillcompileifpublicTree(){Plant();}isaddedtotheTreeclass.
C.ThecodewillcompileifpublicPlant(){Tree();}isaddedtothePlantclass.
D.ThecodewillcompileifpublicPlant(){this(”fern”);}isaddedtothePlantclass.
E.ThecodewillcompileifpublicPlant(){Plant(”fern”);}isaddedtothePlantclass.
第1题:
A.ThetimetofindthevaluefromHashMapwithaPersonkeydependsonthesizeofthemap.
B.DeletingaPersonkeyfromaHashMapwilldeleteallmapentriesforallkeysoftypePerson.
C.InsertingasecondPersonobjectintoaHashSetwillcausethefirstPersonobjecttoberemovedasaduplicate.
D.ThetimetodeterminewhetheraPersonobjectiscontainedinaHashSetisconstantanddoesNOTdependonthesizeofthemap.
第2题:
分析如下代码,其中this关键字的意思是 public class Demo{ private String name; public String getName(){ return name; } public void setName(String name){ this.name = name; } }
A.name属性
B.Demo类种内部指代当前对象的引用
C.Demo类引用所在的方法
D.Demo类中对重载构造方法的引用
第3题:
如下所示的Java代码,其中this关键字的意思是 public class Test { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; //this关键字所在的行 } }
A.name属性
B.Test类的内部指代自身的引用
C.Test类的对象引用Test类的其他对象
D.指所在的方法
第4题:
interface Playable {
void play();
}
interface Bounceable {
void play();
}
interface Rollable extends Playable, Bounceable {
Ball ball = new Ball("PingPang");
}
class Ball implements Rollable {
private String name;
public String getName() {
return name;
}
public Ball(String name) {
this.name = name;
}
public void play() {
ball = new Ball("Football");
System.out.println(ball.getName());
}
}
这个错误不容易发现。
错。"interface Rollable extends Playable, Bounceable"没有问题。interface 可继承多个
interfaces,所以这里没错。问题出在interface Rollable 里的"Ball ball = new Ball("PingPang");"。
任何在interface 里声明的interface variable (接口变量,也可称成员变量),默认为public static
final。也就是说"Ball ball = new Ball("PingPang");"实际上是"public static final Ball ball = new
Ball("PingPang");"。在Ball 类的Play()方法中,"ball = new Ball("Football");"改变了ball 的
reference,而这里的ball 来自Rollable interface,Rollable interface 里的ball 是public static final
的,final 的object 是不能被改变reference 的。因此编译器将在"ball = new Ball("Football");"
这里显示有错。
第5题:
分析如下代码,其中this关键字的意思是 public class Demo{ private String name; public String getName(){ return name; } public void setName(String name){ this.name = name; } }
A.name属性
B.Demo类中内部指代当前对象的引用
C.Demo类引用所在的方法
D.Demo类中对重载构造方法的引用