Hi All,
See this Question. I don't think the valid answers are A, D,E
only (y == z) return true.
2:Which comparisions are true for the following?
C x = new C(10L);
C y = new C(10L);
C z = y;
Long a = 10L;
int b = 10;
A:a == b
B:a == x
C:x == y
D:y == z // Only this return "True"
E:a == 10.0
To
Test the above Question...I wrote the code
class C{
C(long l){}
}
class Test{
public static void main(String[]args){
C x = new C(10L);
C y = new C(10L);
C z = y;
Long a = 10L;
int b = 10;
System.out.println("a == b : "+ (a == b) );
System.out.println("a == x : "+ (a == x ));
System.out.println("x == y : "+ (x == y) );
System.out.println("y == z : "+ (y == z ));
System.out.println("a == 10.0 : " + (a == 10.0) );
}
When I executed I got the following o/p.
C:\Java\bin>javac Test.java
Test.java:23: Incompatible type for declaration. Can't convert long to java.lang.Long.
Long a = 10L;
^
Test.java:26: Incompatible type for java.lang.Long. Can't convert java.lang.Long to int.
System.out.println("a == b : "+ (a == b) );
^
Test.java:27: Incompatible type for java.lang.Long. Can't convert java.lang.Long to C.
System.out.println("a == x : "+ (a == x ));
^
Test.java:30: Incompatible type for java.lang.Long. Can't convert java.lang.Long to double.
System.out.println("a == 10.0 : " + (a == 10.0) );
^
4 errors
Do let me know if I am wrong.
Aruna
[This message has been edited by Aru (edited September 21, 2000).]