This is java.

Source: Internet
Author: User

The code snippet:
12345 byteb1=1,b2=2,b3,b6; final byteb4=4,b5=6; b6=b4+b5; b3=(b1+b2); System.out.println(b3+b6);
The description of the above code snippet is correct ()
    • Output results: 13
    • Statement: B6=B4+B5 Compilation error
    • Statement: B3=B1+B2 Compilation error
    • Run-time Exception thrown

Analysis:

The data type of the expression is automatically lifted, with respect to the automatic elevation of the type, with the following rules in mind.

① all the values of the Byte,short,char type will be promoted to the int type;

② if one operand is long, the result is a long type;

③ if one of the operands is a float type, the result is a float type;

④ if one of the operands is of type double, the result is a double type, whereas a variable declared as final is optimized by the JVM, and the 6th line equals B6 = 10 The addition of a variable without a final modifier is automatically promoted to int, incompatible with the target type byte. Requires a cast (downward transition). C. The final modified variable is a constant, where the b6=b4+b5 can be regarded as b6=10; at compile time it becomes b6=10 and B1 and B2 are byte types, and in Java, they are promoted to int type, and then calculated, b1+ The B2 is already an int type, the assignment to B3,b3 is a byte type, the type does not match, the compilation does not pass, and a cast is required. Byte,short,char in Java is promoted to the int type when it is evaluated. 1. Requires a cast (downward transition).
2. Variables that are not final modified are automatically promoted to type int, incompatible with the target type Byte, and are transformed downward. 2--The following code runs the result is ()
123456789101112131415161718 public class Test{     public int add(int a,int b){            try {             return a+b;               }         catch (Exception e) {              System.out.println("catch语句块");         }         finally{              System.out.println("finally语句块");         }         return 0;    }      public static void main(String argv[]){          Test test =new Test();          System.out.println("和是:"+test.add(9, 34));      }}

    • Catch statement block, and yes: 43
    • Compile exception
    • Finally statement block, and yes: 43
    • And yes: 43,finally statement block

Analysis:

The answer is C for return in the try block, first evaluates the expression after return, the cached result jumps to the finally statement block, and if there is a return statement in the finally statement block, the statement in the try is no longer executed. If there is no return statement in Finally, the following Java program code is executed again in the TRY statement block, after which the result is ().
1234 java.util.HashMap map=newjava.util.HashMap(); map.put("name",null);      map.put("name","Jack");System.out.println(map.size());

    • 0
    • Null
    • 1
    • 2
      Analysis:
C.hashmap is the implementation class of the map interface, and does not guarantee that the order of the elements is constant, its underlying use is the array and the linked list, through the hashcode () Method and the Equals method guarantee the uniqueness of the key hashmap allow null keys and null values to add elements to hashmap using the Put method, add the element if the key does not exist, and return NULL if the key already exists, overwriting the value corresponding to the key, and returning the original key. Since the key is "name", the second addition will overwrite the first value, and return the first key, so there is only one element in HashMap Map set no duplicates, the list is stored sequentially.

This is java.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.