单选题:Java程序阅读-基础知识
设有下面Java程序,请阅读程序并完成选择,以下哪个表达式的值为true?
public class Sample{
long length;
public Sample(long l){ length = l; }
public static void main(String arg[]){
Sample s1, s2, s3;
s1 = new Sample(21L);
s2 = new Sample(21L);
s3 = s2;
long m = 21L;
}
}
A.s1 == s2;
B. s2 == s3;
C.m == s1;
D.s1.equals(m);
answer:B
public class Sample{
long length;
public Sample(long l){ length = l; }
public static void main(String arg[]){
Sample s1, s2, s3;
s1 = new Sample(21L);
s2 = new Sample(21L);
s3 = s2;
long m = 21L;
}
}
A.s1 == s2;
B. s2 == s3;
C.m == s1;
D.s1.equals(m);
answer:B