Java Basic data type conversions
Data types in Java, categorized as reference data types and basic data types. The basic data type is 8
Integer: Byte 8-bit, short 16-bit, int 32-bit. Long 64 bits, (8 bits = 1 bytes)
Float type: Float 32-bit, double64-bit
Character type: Char
Boolean Type: Boolean
Automatic type conversion
Conversion diagram
The positive direction is the auto-convert inverse direction cast (char--->double conversion and byte-to-double conversion)
Char-->int-->long-->float-->doubl
Byte-->shot-->int-->long-->float-->double
The interview questions are as follows
1. Will the following code compile pass?
public class test{public static void Main (string[] args) {byte a=1; BYTE b=a+1; }} A: The type conversion error will be prompted when the a+1 operation is not automatically promoted to type int.
2. The following code compilation will pass, if compiled through, what output?
test{Main (string[] args) {a=; B=++a; System: println (+B); }} A: Compiled through, because + + + + is the Java language specified by the operator, Java will be special processing. Output: b=2;
This article is from the "Java Learning route" blog, reproduced please contact the author!
Java Basic Learning Chapter 02 (data type conversion and fundamental questions)