Java Novice Road--day 04 data type conversions

Source: Internet
Author: User

Automatic type conversion:
When the byte type is added to the int type, the byte type data is automatically promoted to int type data.
(Regular: Byte-to-byte conversions with a small footprint)
Attention! The conversion is valid only for constants, and variables do not convert!
For example:

Run error, Tip accuracy missing

Analysis: 3 is an int constant that can be automatically converted to byte, but B is a variable and cannot be automatically converted
For example, the following situation would overflow

String and any number with a + connection, representing the connection, to form a new string

To force type conversions:

  1. Char is a character data that converts integer data to the corresponding character according to an ASCII-encoded table, output a
  2. ' A ' is a character type data, so no conversion, output a
  3. ' A ' is the character data, 1 is the int type data, because the char data occupies 2 bytes, int occupies 4 bytes, the sum is the int type data, the output 98
  4. (char+1) is of type int, char (char+1) cast type is character data, output B

Java Novice Road--day 04 data type conversions

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.