본문 바로가기
콤퓨타/JAVA

자동 형변환

by 어니엉 2013. 2. 20.
728x90

변수1

변수2

결과 값

byte

byte

int

byte

short

int

int

byte

int

short

int

int

int

int

int


변수1

변수2

결과 값

long

int

long

long

long

long

byte

float

float

int

float

float

long

float

float

float

double

double

double

double

double


int보다 작거나 같은 형이 연산된 결과 값은 모두 int

-> JAVA는 4바이트 단위로 처리하기 때문

4바이트 이상의 변수들의 연산은 자료형이 큰 쪽으로 형 변환 된다.

ex)

byte b1=1;

byte b2=2;

byte b3 = b1+b2; (x)

int b3 = b1+b2; (o)

728x90

'콤퓨타 > JAVA' 카테고리의 다른 글

static, final  (0) 2013.02.20
System.out.println()  (0) 2013.02.20
자료형 종류, 크기 및 표기  (0) 2013.02.20
객체지향의 특징  (0) 2013.02.20
Java 언어의 특징 및 장점  (0) 2013.02.20

댓글