网友您好, 请在下方输入框内输入要搜索的题目:

题目内容 (请给出正确答案)
单选题
class Sock2 {   String color;   public boolean equals(Object o) {   return color.equals(((Sock2)o).color);   } }   class TestSocks {   public static void main(String [] args) {   Sock2 s1 = new Sock2(); s1.color = "blue";   Sock2 s2 = new Sock2(); s2.color = "blue";   if (s1.equals(s2)) System.out.print("equals ");   if (s1 == s2) System.out.print("== ");   }   }   结果为:()
A

==

B

equals

C

equals ==

D

无结果输出


参考答案

参考解析
解析: 暂无解析
更多 “单选题class Sock2 {   String color;   public boolean equals(Object o) {   return color.equals(((Sock2)o).color);   } }   class TestSocks {   public static void main(String [] args) {   Sock2 s1 = new Sock2(); s1.color = "blue";   Sock2 s2 = new Sock2(); s2.color = "blue";   if (s1.equals(s2)) System.out.print("equals ");   if (s1 == s2) System.out.print("== ");   }   }   结果为:()A ==B equalsC equals ==D 无结果输出” 相关考题
考题 【Java代码】import Java.util.ArrayList;import java.util.List;(1) class AbstractFile{protected String name;public void printName(){System.out.println(name);}public abstract boolean addChild(AbstractFile file);public abstract boolean removeChild(AbstractF ile file);public abstract ListAbstractFile getChildren();}class File extends AbstractFile{public File(String name){this.name=name;}public boolean addChild(AbstractFile file){return false;}public boolean removeChild(AbstractFile file){return false;}public ListAbstractFile getChildren(){return (2) ;}}class Folder extends AbstractFile{private List AbslractFile childList;public Folder(String name){this.name=name;this.childList=new ArrayListAbstractFile();}public boolean addChild(AbstractFile file) { return childList.add(file);}public boolean removeChild(AbstractFile file){return childList.remove(file);}public (3) AbstractFile getChildren(){return (4) ;}}public class Client{public static void main(String[] args){//构造一个树形的文件/目录结构AbstractFile rootFolder= new Folder("c:\\ ");AbstractFile compositeFolder=new Folder("composite");AbstractFile windowsFolder=new Folder("windows");AbstractFile file=new File("TestComposite.java");rootFolder.addChild(compositeFolder) ;rootFolder.addChild(windowsFolder);compositeFolder.addChild(file) ;//打印目录文件树printTree(rootFolder);}private static void printTree(AbslractFile ifile){ifile.printName();List AbslractFile children=ifile.getChildreno:if(children==null) return;for (AbstractFile file:children) {(5) ;}}}该程序运行后输出结果为:c:\compositeTestComposite.javaWindows

考题 下列语句输出结果为( )。 public class test\ { public static void main (String args[]) { String s1=new String("How"); String s2=new String("How"); System.out.println(!(s1.equals(s2))); } }A.falseB.trueC.0D.1

考题 classSock2{Stringcolor;publicbooleanequals(Objecto){returncolor.equals(((Sock2)o).color);}}classTestSocks{publicstaticvoidmain(String[]args){Sock2s1=newSock2();s1.color=blue;Sock2s2=newSock2();s2.color=blue;if(s1.equals(s2))System.out.print(equals);if(s1==s2)System.out.print(==);}}结果为:()A.==B.equalsC.equals==D.无结果输出

考题 Java代码查错1.abstract class Name {private String name;public abstract boolean isStupidName(String name) {}}大侠们,这有何错误?

考题 下列程序的运行结果为______。 class A { int b=0; } public class ex35 public static void main(String args[]) { ex35 t=new ex35(); t.method(); } void method() { A A1=new A(); A A2=new A(); A1,b=A2.b=12; boolean b=A1.equals(A2); Syatem.out.println(b); } }A.trueB.falseC.0D.1

考题 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;

考题 public class ClassA{ public int getValue(){ int value=0; boolean setting=true; String title="Hello"; if(value||(setting title=="Hello")){return 1;} if(value==1title.equals("Hello")){return 2;} } } And: ClassA a=new ClassA(); a.getValue(); What is the result?()A、1B、2C、Compilation fails.D、The code runs with no output.E、An exception is thrown at runtime.

考题 Which statements concerning the following code are true?()   class a {   public a() {}   public a(int i) { this(); }   }   class b extends a {   public boolean b(String msg) { return false; }   }   class c extends b  {  private c() { super(); }   public c(String msg) { this(); }   public c(int i) {}   }  A、The code will fail to compile.B、The constructor in a that takes an int as an argument will never be called as a result of constructing an  object of class b or c.C、Class c has three constructors.D、Objects of class b cannot be constructed.E、At most one of the constructors of each class is called as a result of constructing an object of class c.

考题 class Sock2 {   String color;   public boolean equals(Object o) {   return color.equals(((Sock2)o).color);   } }   class TestSocks {   public static void main(String [] args) {   Sock2 s1 = new Sock2(); s1.color = "blue";   Sock2 s2 = new Sock2(); s2.color = "blue";   if (s1.equals(s2)) System.out.print("equals ");   if (s1 == s2) System.out.print("== ");   }   }   结果为:()      A、==B、equalsC、equals ==D、无结果输出

考题 程序员正在进行一个项目,必须实现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); }

考题 以下哪些方法在Object类中定义()。A、toString()B、equals(Objecto)C、public static void main(String[]args)D、System.out.println()E、wait()

考题 class Sock {  String size;  String color;  public boolean equals(Object o) {  Sock s = (Sock) o;  return color.equals(s.color);   }  // insert code here  }  哪两个满足 hashCode 的约定?()A、public int hashCode() { return 343; }B、public int hashCode() { return size.hashCode (); }C、public int hashCode() { return color.hashCode (); }D、public int hashCode() { return (int) (Math.random() * 1000);

考题 public class X {  public static void main (String[]args)  {  String s1 = new String (“true”);  Boolean b1 = new Boolean (true);  if (s2.equals(b1))   {  System.out.printIn(“Equal”);  }  }  }      What is the result?()  A、 The program runs and prints nothing.B、 The program runs and prints “Equal”C、 An error at line 5 causes compilation to fail.D、 The program runs but aborts with an exception.

考题 public class Person {  private name;  public Person(String name) {  this.name = name;  }  public boolean equals(Object o) {  if( !o instanceof Person ) return false;  Person p = (Person) o;  return p.name.equals(this.name);  }  }  Which is true?() A、 Compilation fails because the hashCode method is not overridden.B、 A HashSet could contain multiple Person objects with the same name.C、 All Person objects will have the same hash code because the hashCode method is not overridden.D、 If a HashSet contains more than one Person object with name=”Fred”, then removing another person, also with name=”Fred”, will remove them all.

考题 public class Key {  private long id1;  private long 1d2;  // class Key methods  }  A programmer is developing a class Key, that will be used as a key in a standard java.util.HashMap. Which two methods should be overridden to assure that Key works correctly as a key?()A、 public int hashCode()B、 public boolean equals(Key k)C、 public int compareTo(Object o)D、 public boolean equals(Object o)E、 public boolean compareTo(Key k)

考题 单选题public class Person {  private name;  public Person(String name) {  this.name = name;  }  public boolean equals(Object o) {  if( !o instanceof Person ) return false;  Person p = (Person) o;  return p.name.equals(this.name);  }  }  Which is true?()A  Compilation fails because the hashCode method is not overridden.B  A HashSet could contain multiple Person objects with the same name.C  All Person objects will have the same hash code because the hashCode method is not overridden.D  If a HashSet contains more than one Person object with name=”Fred”, then removing another person, also with name=”Fred”, will remove them all.

考题 多选题Which statements concerning the following code are true?()   class a {   public a() {}   public a(int i) { this(); }   }   class b extends a {   public boolean b(String msg) { return false; }   }   class c extends b  {  private c() { super(); }   public c(String msg) { this(); }   public c(int i) {}   }AThe code will fail to compile.BThe constructor in a that takes an int as an argument will never be called as a result of constructing an  object of class b or c.CClass c has three constructors.DObjects of class b cannot be constructed.EAt most one of the constructors of each class is called as a result of constructing an object of class c.

考题 单选题1. public class Person {  2. private String name;  3. public Person(String name) { this.name = name; }  4. public boolean equals(Person p) {  5. return p.name.equals(this.name);  6. }  7. }  Which is true?()A  The equals method does NOT properly override the Object.equals method.B  Compilation fails because the private attribute p.name cannot be accessed in line 5.C  To work correctly with hash-based data structures, this class must also implement the hashCode method.D  When adding Person objects to a java.util.Set collection, the equals method in line 4 will prevent duplicates.

考题 单选题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);

考题 单选题1. abstract class Color2 {   2. //insert code here   3. }   4.   5. public class Blue2 extends Color2 {   6. public String getRGB() { return "blue"; }   7. }   和4个声明:   public abstract String getRGB();   abstract String getRGB();   private abstract String getRGB();   protected abstract String getRGB();   分别插入到第2行,有多少行可以编译?()A 0B 1C 2D 3

考题 单选题public class X {   public static void main (Stringargs) {   String s1 = new String (“true”);   Boolean b1 = new Boolean (true);   if (s2.equals(b1)) {   System.out.printIn(“Equal”);   }   }   }   What is the result? ()A  The program runs and prints nothing.B  The program runs and prints “Equal”C  An error at line 5 causes compilation to fail.D  The program runs but aborts with an exception.

考题 单选题public class ClassA{ public int getValue(){ int value=0; boolean setting=true; String title="Hello"; if(value||(setting title=="Hello")){return 1;} if(value==1title.equals("Hello")){return 2;} } } And: ClassA a=new ClassA(); a.getValue(); What is the result?()A 1B 2C Compilation fails.D The code runs with no output.E An exception is thrown at runtime.

考题 单选题public class X {  public static void main (String[]args)  {  String s1 = new String (“true”);  Boolean b1 = new Boolean (true);  if (s2.equals(b1))   {  System.out.printIn(“Equal”);  }  }  }      What is the result?()A  The program runs and prints nothing.B  The program runs and prints “Equal”C  An error at line 5 causes compilation to fail.D  The program runs but aborts with an exception.

考题 单选题现有:  1. abstract class Color2  {      2.    //insert code here      3.  }      4.  5. public class Blue2 extends Color2  {  6.public  String getRGB()  {  return  "blue";  }      7.  }  和4个声明:  public abstract  String getRGB();     abstract  String getRGB();  private abstract  String getRGB();      protected abstract String getRGB();  分别插入到第2行,有多少行可以编译?()A   0B   1C   2D   3

考题 多选题public class Key {  private long id1;  private long 1d2;  // class Key methods  }  A programmer is developing a class Key, that will be used as a key in a standard java.util.HashMap. Which two methods should be overridden to assure that Key works correctly as a key?()Apublic int hashCode()Bpublic boolean equals(Key k)Cpublic int compareTo(Object o)Dpublic boolean equals(Object o)Epublic boolean compareTo(Key k)

考题 单选题程序员正在进行一个项目,必须实现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);  }