Summary
1, = = operator comparison is whether the operand number is the same object; the other = = = = the operator must be the same type (can be between the parent subclass) to compile.
2, string Equals () method is compared to whether the content of the two String objects is the same
3, = = Compare the address, if it is a specific Arabic number comparison, the value is TRUE, such as:
INT A = 10 and long b = 10L and Double C = 10.0 are the same (True) because they all point to the stack of the address 10; if the following question 111;
String s = "hello";
String t = "hello";
CHAR C [] = {'h', 'e', 'L', 'L', 'o'}
Which returnes?
A. S.Equals (T);
B. T. Equals (C);
C. s == T;
D. T. Equals (New String ("Hello");
E. T == C.
Answer: (ACD)
Title: What are you returning to true.
This is discussed in the discussion of the equals () method and == operator in the previous item 10. == The operator is compared to whether the operand number is the same object, and the String's equals () method is compared to whether the contents of the two String objects are the same, and the parameters are like a String object, it is possible to return TRUE Other objects return false. It is to be pointed out because S and T are not created by NEW, they point to the same string in the memory pool, so its address is actually the same (this can be obtained from the result of referring to a simple test program, limited to The space does not list the test code and the anti-compilation analysis, so the answer C is also correct.
Given The Following Class:
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;
}
}
Which Expression Returns True?
A. S1 == S2;
B. S2 == S3;
C. m == S1;
D. S1.Equals (m).
Answer: (b) // D is wrong, only string Equals () method is worth a value;
Title: Give the following class: ...
Which expression returns True.
The characteristics of the Equals () method that have been described above have been described above, and the operand on both sides of the operator must be the same type (can be between the parent son class) to compile.
Look at the following
17. float f = 4.2f;
Float g = new float (4.2f);
Double D = New Double (4.2);
Which is true?
A. f = = g B. g = = g C. D = = f D. D. Equals (f) e d.equals (g) F. g.Equals (4.2); answer: B
93. Click The EXHIBIT button:
Public class x {
2. Public static void main (String [] args) {
3. String S1 = New String ("true");
4. Boolean B1 = New Boolean (TRUE);
5. IF (s2.equals (b1)) {
6. System.out.printin ("Equal");
7.} 8.} 9.
What is the result?
A. The Program Runs and Prints Nothing.
B. The Program Runs and Prints "Equal."
C. An Error At Line 5 Causees CompiLation To Fail.
D. The Program Runs But Aborts with an exception.
Answer: a
Compare the next question, be careful to use Equals and = =.
93. Click The EXHIBIT button:
Public class x {
2. Public static void main (String [] args) {
3. String S1 = New String ("true");
4. Boolean B1 = New Boolean (TRUE);
5. IF (S2 = = b1) {// = = Operator on both sides must be the same type (can be between the parent son class) to compile
6. System.out.printin ("Equal");
7.} 8.} 9.
What is the result?
A. The Program Runs and Prints Nothing.
B. The Program Runs and Prints "Equal."
C. An Error At Line 5 Causees CompiLation To Fail.
D. The Program Runs But Aborts with an exception.
Answer: c
111. Given:
Public class foo {
2. Private int val;
3. Public foo (int V) (VAL = v;)}
4. Public static void main (String [] args) {
5. foo a = new foo (10);
6. foo b = new foo (10);
7. foo c = a;
8. INT D = 10;
9. Double E = 10.0;
10.}
11.}
Which THREE LOGICAL EXPRESSITIONS EVALUATE TO TRUE? (Choose Three)
A. (a == c)
B. (D == E)
C. (b == d)
D. (a == b)
E. (b == c)
F. (d == 10.0)
Answer: ABF / / = = Compare the address, they all point to the stack of the address 10;
Given The Following Code, What Test Would You NEED TO PUT IN Place Offst Line?
// Place Test Here To Result in An Output of The String Equal
Public class eqtest {
Public static void main (String Argv []) {
EQTEST E = New EQTEST ();
}
EQTEST () {
String s = "java";
String S2 = "java"; // Careful case
// Place test here {
System.out.println ("Equal");
Else
{
System.out.println ("Not Equal");
}
}
}
1) IF (s == S2)
2) IF (S.Equals (S2)
3) IF (S.EqualsignoreCase (S2))
4) IF (S.NocaseMatch (S2))
Answer: 3) // Carefully write