byte > short > int > long > float > double
작은거에서 큰거를 저장 (자동 형변환)
예>
byte b=1; //그릇 = 값
short b2 = b;
int b3 = b2;
long b4 = b3;
float b5 = b4;
double b6 = b5;
강제 형 변환 또는 ‘type casting' 이라고 한다.
강제적으로 데이터형을 변경하는 개념이기 때문에
데이터 손실이 발생할 수 있다.
예>
public class Test {
public static void main(String[] args) {
int a = 1;
double b = 4.5;
double c = (int) a + (int) b;
double d = (int) a + (double) b;
double e = (double)a + (double)b;
System.out.println(c);
System.out.println(d);
System.out.println(e);
}
}
실행결과