publicclassPlant{privateStringname;publicPlant(Stringname){this.name=name;}publicStringgetName(){returnname;}}publicclassTreeextendsPlant{publicvoidgrowFruit(){}publicvoiddropLeaves(){}}Whichistrue?() A.Thecodewillcompilewithoutchanges.B.ThecodewillcompileifpublicTree(){Plant();}isaddedtotheTreeclass.C.ThecodewillcompileifpublicPlant(){Tree();}isaddedtothePlantclass.D.ThecodewillcompileifpublicPlant(){this(”fern”);}isaddedtothePlantclass.E.ThecodewillcompileifpublicPlant(){Plant(”fern”);}isaddedtothePlantclass.

publicclassPlant{privateStringname;publicPlant(Stringname){this.name=name;}publicStringgetName(){returnname;}}publicclassTreeextendsPlant{publicvoidgrowFruit(){}publicvoiddropLeaves(){}}Whichistrue?()

A.Thecodewillcompilewithoutchanges.

B.ThecodewillcompileifpublicTree(){Plant();}isaddedtotheTreeclass.

C.ThecodewillcompileifpublicPlant(){Tree();}isaddedtothePlantclass.

D.ThecodewillcompileifpublicPlant(){this(”fern”);}isaddedtothePlantclass.

E.ThecodewillcompileifpublicPlant(){Plant(”fern”);}isaddedtothePlantclass.


相关考题:

publicclassEmployee{privateStringname;publicEmployee(Stringname){this.name=name;}publicStringgetName(){returnname;}}publicclassManagerextendsEmployee{privateStringdepartment;publicManager(Stringname,Stringdepartment){this.department=department;super(name);(应于上一行掉位置)System.out.println(getName());}}Super的位置是否在方法的首行执行语句newManager(smith”,”SALES”)后程序的输出是哪项?()A.smithB.nullC.SALESD.编译错误

publicclassPerson{2.privateStringname;3.publicPerson(Stringname){this.name=name;}4.publicbooleanequals(Personp){5.returnp.name.equals(this.name);6.}7.}Whichistrue?() A.TheequalsmethoddoesNOTproperlyoverridetheObject.equalsmethod.B.Compilationfailsbecausetheprivateattributep.namecannotbeaccessedinline5.C.Toworkcorrectlywithhash-baseddatastructures,thisclassmustalsoimplementthehashCodemethod.D.WhenaddingPersonobjectstoajava.util.Setcollection,theequalsmethodinline4willpreventduplicates.

publicclassPerson{privatename;publicPerson(Stringname){this.name=name;}publicbooleanequals(Objecto){if(!oinstanceofPerson)returnfalse;Personp=(Person)o;returnp.name.equals(this.name);}}Whichistrue?() A.CompilationfailsbecausethehashCodemethodisnotoverridden.B.AHashSetcouldcontainmultiplePersonobjectswiththesamename.C.AllPersonobjectswillhavethesamehashcodebecausethehashCodemethodisnotoverridden.D.IfaHashSetcontainsmorethanonePersonobjectwithname=”Fred”,thenremovinganother person,alsowithname=”Fred”,willremovethemall.

publicclassNamedCounter{privatefinalStringname;privateintcount;publicNamedCounter(Stringname){this.name=name;}publicStringgetName(){returnname;}publicvoidincrement(){coount++;}publicintgetCount(){returncount;}publicvoidreset(){count=0;}}Whichthreechangesshouldbemadetoadaptthisclasstobeusedsafelybymultiplethreads?()A.declarereset()usingthesynchronizedkeywordB.declaregetName()usingthesynchronizedkeywordC.declaregetCount()usingthesynchronizedkeywordD.declaretheconstructorusingthesynchronizedkeywordE.declareincrement()usingthesynchronizedkeyword

publicclassPerson{privatename;publicPerson(Stringname){this.name=name;}publicinthashCode(){return420;}}Whichistrue?() A.ThetimetofindthevaluefromHashMapwithaPersonkeydependsonthesizeofthemap.B.DeletingaPersonkeyfromaHashMapwilldeleteallmapentriesforallkeysoftypePerson.C.InsertingasecondPersonobjectintoaHashSetwillcausethefirstPersonobjecttoberemovedasaduplicate.D.ThetimetodeterminewhetheraPersonobjectiscontainedinaHashSetisconstantanddoesNOTdependonthesizeofthemap.

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());}}这个错误不容易发现。

分析如下代码,其中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类中对重载构造方法的引用

分析如下代码,其中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类中对重载构造方法的引用

如下所示的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.指所在的方法