Files
javaSE251223/day02/src/com/inmind/Demo01.java

24 lines
793 B
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.inmind;
/*
自动转换:将取值范围小的类型自动提升为取值范围大的类型
*/
public class Demo01 {
public static void main(String[] args) {
//定义2个int变量4个字节
int a = 10;
int b = 20;
//2个整数相加
int sum = a+b;
System.out.println(sum);//30
//定义一个字节型变量1个字节
byte b1 = 2;
int sum1 = a+b1;//先将1字节的b1,自动提升转换为4字节的int型再进行计算的
System.out.println(sum1);//12
//12的整数是可以被一个byte所表示
//byte b2 = a+b1;//错误a+b1发生了自动类型转换计算之后是一个4字节的int型的值是不能直接赋值给1字节的类型
}
}