33、一般在覆盖时,要同时覆盖hashCode、equals方法。

33、一般在覆盖时,要同时覆盖hashCode、equals方法。


参考答案和解析
A

相关考题:

Object类中的方法public int hashCode(),在其子类中覆盖该方法时,其方法修饰符可以是______。A) protectedB) publicC) privateD) 缺省A.B.C.D.

classSock{Stringsize;Stringcolor;publicbooleanequals(Objecto){Socks=(Sock)o;returncolor.equals(s.color);}//insertcodehere}哪两个满足hashCode的约定?() A.publicinthashCode(){return343;}B.publicinthashCode(){returnsize.hashCode();}C.publicinthashCode(){returncolor.hashCode();}D.publicinthashCode(){return(int)(Math.random()*1000);

程序员正在进行一个项目,必须实现equals方法与所给的hashCode方法协调运行:()publicinthashCode(){return(size.hashCode()+color.hashCode())*17;}哪一个equals方法支持此目标?() A.无法确定B.publicbooleanequals(Objecto){Socks=(Sock)o;returnsize.equals(s.size);}C.publicbooleanequals(Objecto){Socks=(Sock)o;returncolor.equals(s.color);}D.publicbooleanequals(Objecto){Socks=(Sock)o;returnsize.equals(s.size)color.equals(s.color);}

publicclassPerson{privateStringname,comment;privateintage;publicPerson(Stringn,inta,Stringc){name=n;age=a;comment=c;}publicbooleanequals(Objecto){if(!(oinstanceofPerson))returnfalse;Personp=(Person)o;returnage==p.agename.equals(p.name);}}WhatistheappropriatedefinitionofthehashCodemethodinclassPerson?()A.returnsuper.hashCode();B.returnname.hashCode()+age*7;C.returnname.hashCode()+comment.hashCode()/2;D.returnname.hashCode()+comment.hashCode()/2-age*3;

Object类中的方法public int hashCode[],在其子类中覆盖该方法时,其方法修饰符可以是( )。A.protectedB.publicC.privateD.缺省

下列有关HashSet集合的描述中,错误的是() A.HashSet是Set接口的一个实现类B.向HashSet存入对象时,对象一般会重写hashCode ()和equals ()方法C.向HashSet存入对象时,对象的equals ()方法一定会被执行D.HashSet存储的元素是不可重复的

public class Person {  private String name, comment;  private int age;  public Person(String n, int a, String c) {  name = n; age = a; comment = c;  }  public boolean equals(Object o) {  if(! (o instanceof Person)) return false;  Person p = (Person)o;  return age == p.age  name.equals(p.name);  }  }  What is the appropriate definition of the hashCode method in class Person?() A、 return super.hashCode();B、 return name.hashCode() + age * 7;C、 return name.hashCode() + comment.hashCode() /2;D、 return name.hashCode() + comment.hashCode() / 2 - age * 3;

程序员正在进行一个项目,必须实现equals方法与所给的hashCode方法协调运行:()  public int hashCode() {   return (size.hashCode() + color.hashCode()) * 17;   }   哪一个equals方法支持此目标?()  A、 无法确定B、 public boolean equals(Object o) {  Sock s = (Sock) o;return size.equals(s.size);  } C、 public boolean equals(Object o) {  Sock s = (Sock) o;return color.equals(s.color); }D、 public boolean equals(Object o) {  Sock s = (Sock) o;return size.equals(s.size) color.equals(s.color); }

下面有关方法覆盖说法不正确的是()。A、方法覆盖要求覆盖和被覆盖的方法有相同的名字,参数列以及返回值B、方法覆盖要求覆盖和被覆盖的方法必须具有相同的访问权限C、覆盖的方法不能比被覆盖的方法抛出更多的异常D、覆盖的方法一定不能是private的

如果你设计了一个类,并且覆盖了equals( )方法,哪些方法你还会考虑覆盖()A、clone()B、toString()C、wait()D、finalize()E、hashCode()

在实际的逻辑覆盖测试中,一般以()为主设计测试用例。A、条件覆盖B、判定覆盖C、条件组合覆盖D、路径覆盖

逻辑覆盖测试包括的常用覆盖方法有:语句覆盖,判定覆盖,条件覆盖,判定-条件覆盖、条件组合覆盖、路径覆盖。

覆盖包括的常用覆盖方法有:()、分支覆盖、条件覆盖、判定-条件覆盖、路径覆盖。

关于天线选型,以下说法正确的是:()A、在密集城区,为了保障覆盖均匀连续,应该选用全向天线B、天线的水平波瓣角越窄,增益越大。所以为了保证覆盖,尽可能选用水平波瓣角小的天线,例如33°天线C、天线的垂直波瓣角对于覆盖没有影响,一般规划中不会考虑D、对于平直公路的覆盖,为了使覆盖尽可能远,一般选用33度的窄波瓣角天线

两个对像值相同(x.equals(y)==true),但却可有不同的hashcode,这句话对不对?

HashSet子类依靠()方法区分重复元素。A、toString()、equals()B、clone()、equals()C、hashCode()、equals()D、getClass()、clone()

关于天线选型,以下说法正确的是哪个?()A、在密集城区,为了保障覆盖均匀连续,应该选用高增益的全向天线B、天线的水平波瓣焦越窄,增益越大,所以为了保障覆盖,尽可能选用水平波瓣角度小的天线C、天线的垂直波瓣角对于覆盖没有影响,一般规划中不会考虑D、对于平直公路的覆盖,为了使覆盖尽可能的远,一般采用33度的窄波瓣角的天线

软件测试的目的是__(1)__。通常__(2)__是在代码编写阶段可进行的测试,它是整个测试工作的基础。逻辑覆盖的标准主要用于__(3)__。它主要包括条件覆盖、条件组合(多重条件)覆盖、判定覆盖、条件及判定覆盖、语句覆盖和路径覆盖等几种,其中除了路覆盖外最弱的覆盖标准是__(4)__,最强的覆盖标准是__(5)__。空白(3)处应选择()A、黑盒测试方法B、白盒测试方法C、灰盒测试方法D、软件验证方法

Which two statements are true regarding the return values of property written hashCode and equals methods from two instances of the same class?()A、 If the hashCode values are different, the objects might be equal.B、 If the hashCode values are the same, the object must be equal.C、 If the hashCode values are the same, the objects might be equal.D、 If the hashCode values are different, the objects must be unequal.

填空题覆盖包括的常用覆盖方法有:()、分支覆盖、条件覆盖、判定-条件覆盖、路径覆盖。

单选题public class Person {  private String name, comment;  private int age;  public Person(String n, int a, String c) {  name = n; age = a; comment = c;  }  public boolean equals(Object o) {  if(! (o instanceof Person)) return false;  Person p = (Person)o;  return age == p.age  name.equals(p.name);  }  }  What is the appropriate definition of the hashCode method in class Person?()A return super.hashCode();B return name.hashCode() + age * 7;C return name.hashCode() + comment.hashCode() /2;D return name.hashCode() + comment.hashCode() / 2 - age * 3;

多选题class Sock {  String size;  String color;  public boolean equals(Object o) {  Sock s = (Sock) o;  return color.equals(s.color);   }  // insert code here  }  哪两个满足 hashCode 的约定?()Apublic int hashCode() { return 343; }Bpublic int hashCode() { return size.hashCode (); }Cpublic int hashCode() { return color.hashCode (); }Dpublic int hashCode() { return (int) (Math.random() * 1000);

多选题Which two statements are true regarding the return values of property written hashCode and equals methods from two instances of the same class?()AIf the hashCode values are different, the objects might be equal.BIf the hashCode values are the same, the object must be equal.CIf the hashCode values are the same, the objects might be equal.DIf the hashCode values are different, the objects must be unequal.

单选题如下关于Java编码描述不正确的是()A除了构建器外,不要使用和类名相同的方法名B使用equals()比较两个类的值是否相同C不要使用嵌套赋值,即在一个表达式中使用多个=D重载equals()方法时,不必要重载hashCode()方法

问答题两个对像值相同(x.equals(y)==true),但却可有不同的hashcode,这句话对不对?

单选题程序员正在进行一个项目,必须实现equals方法与所给的hashCode方法协调运行:  public int hashCode() {    return (size.hashCode() + color.hashCode()) * 17;    }    哪一个equals方法支持此目标?()A 无法确定B public boolean equals(Object o) {  Sock s = (Sock) o; return size.equals(s.size);}C public boolean equals(Object o) {  Sock s = (Sock) o; return color.equals(s.color);}D public boolean equals(Object o) {  Sock s = (Sock) o; return size.equals(s.size) color.equals(s.color);  }

单选题下面有关方法覆盖说法不正确的是()。A方法覆盖要求覆盖和被覆盖的方法有相同的名字,参数列以及返回值B方法覆盖要求覆盖和被覆盖的方法必须具有相同的访问权限C覆盖的方法不能比被覆盖的方法抛出更多的异常D覆盖的方法一定不能是private的

单选题如果你设计了一个类,并且覆盖了equals( )方法,哪些方法你还会考虑覆盖()Aclone()BtoString()Cwait()Dfinalize()EhashCode()