== Difference to Equal

xiaoxiao2021-03-06  65

 Summary 1, = = Operator compares whether the operator is the same object; the other = = = the operator must be the same type (can be between the parent subclass) to compile. 2, String's equals () method is compared to whether the content of the two String objects is 3, = = comparison is address, if it is a specific Arabic number comparison, the value is True, such as int a = 10 LONG B = 10L and Double C = 10.0 are all 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 Return True? A. S.equals (t); b. T.equals (c); c. S == T; D. T. Equals (New String ("Hello")); E. T == C. Answer: (ACD) topic: What to return 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 not right, 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 Are 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: 1. 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 "Equal." Equal. "c. an Error At line 5 Causes Compilation TO Fail.d. The Program Runs But Aborts with an exception. Answ: a Compare the next question, be careful with the difference between equals and = =;  93. Click The Exhibit Button: 1. 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) {// = = Operation on both sides of the operator The number must be the same type (which can be between the parent son class) to compile 6. System.Out.printin ("equally); 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 Causes Compiration To Fail.d. The Program Runs But Aborts with an Exception. Answer: C 111. Given: 1. Public Class Foo { 2. Private int val; 3. Public foo (int 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. = C) B. (D == E) C. (b == d) D. (a == b) E. (b == c) F. (D == 10.0) Answer: ABF / / = = Compare the address,

转载请注明原文地址:https://www.9cbs.com/read-89516.html

New Post(0)