byte类型占一个字节
byte 10为 0000 1010
short类型占两个字节
shrot 10为 0000 0000 0000 1010
int类型占4个字节
long类型z占八个字节
隐式转换:
public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
byte a = 10; //0000 1010
int b = a;// 0000 0000 0000 0000 0000 0000 0000 1010
System.out.println(b);
}
}
强制转换:
public class Main {
public static void main(String[] args) {
int a = 300;
byte b = (byte)a ;
System.out.println(b);
}
}
b的运行结果为44,int转byte前面的都去掉.