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


相关考题:

publicclassEmployee{privateStringname;publicEmployee(Stringname){this.name=name;}publicvoiddisplay(){System.out.print(name);}}publicclassManagerextendsEmployee{privateStringdepartment;publicManager(Stringname,Stringdepartment){super(name);this.department=department;}publicvoiddisplay(){System.out.println(super.display()+”,”+department);}}执行语句newManager(smith”,”SALES”)后程序的输出是哪项?()A.smith,SALESB.null,SALESC.smith,nullD.null,null

类Teacher:classTeacher{Stringname;floatsalary;Teacher(Stringname){this.name=name;}Teacher(Stringname,floatsalary){this.name=name;this.salary=salary;}}执行语句Teachert=newTeacher(Tom”,2000.0f);后,字段salary的值是哪一项?()A.2000.0fB.0.0fC.null;D.2000

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

Giventhismethodinaclass:publicStringtoString(){StringBufferbuffer=newStringBuffer();buffer.append(??);buffer.append(this.name);buffer.append(??);returnbuffer.toString();}Whichistrue?() A.ThiscodeisNOTthread-safe.B.TheprogrammercanreplaceStringBufferwithStringBuilderwithnootherchanges.C.ThiscodewillperformwellandconvertingthecodetouseStringBuilderwillnotenhancetheperformance.D.Thiscodewillperformpoorly.Forbetterperformance,thecodeshouldberewritten:return““+this.name+“”;

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.

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

Person p = new Person(“张三”,23);这条语句会调用下列哪个构造方法给属性进行初始化() A.public Person(){}B.public Person(String name,int age) { this.name = name; this.age = age; }C.public Person(int age,String name) { this.age = age; this.name = name; }D.public Person(String name) { this.name = name; }