单项选择题
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.无结果输出
点击查看答案&解析
相关考题
-
单项选择题
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.0
B.1
C.2
D.3 -
单项选择题
import java.util.*; class Banana3 { public static void main(String [] args) { int x = 2; Banana3 b = new Banana3(); b.go(x); } static { x += x; } void go(int x) { ++x; System.out.println(x); } } 结果为:()
A.2
B.3
C.5
D.编译失败 -
单项选择题
现有如下五个声明: int a_really_really_really_long_variable_name = 5; int _hi =6; int big = Integer.getInteger("7"); int $dollars = 8; int %percent = 9; 有几个可以通过编译?()
A.1
B.2
C.3
D.4
