day20_WrapperEx3

육희영·2021년 11월 1일
0
package com.java1.day20;

import static java.lang.System.*; //System을 생략하고 쓰기위해서...
//Wrapper클래스..일반 자료형을 클래스화 한것이다.
public class WrapperEx3 {
	public static void main(String[] args) {
		Integer i = new Integer(100);
		Integer i2 = new Integer(100);

		out.println("i == i2 ? " + (i == i2)); // 주소를 비교하기때문에 false를 나타낸다

		// Wrapper 클래스들은 모두 equals()가 오버라이딩 되어있어서(String 클래스처럼) 주소값이 아닌 객체가
		// 가지고 있는 값을 비교한다.
		out.println("i.equals(i2) ? " + i.equals(i2));
		out.println("i.compareTo(i2) ? " + i.compareTo(i2));// 같으면 0, 다르면 1

		// toString 메서드도 오버라이딩 되어 있어서 객체가 가지고 있는값을 문자열로 변환하여 반환한다.
		out.println("i.toString()=" + i.toString());

		out.println("MAX_VALUE=" + Integer.MAX_VALUE); // Int가 표현할 수 있는 최대값
		out.println("MIN_VALUE=" + Integer.MIN_VALUE); // Int가 표현할 수 있는 최소값
		out.println("SIZE=" + Integer.SIZE + "bits"); // Int는 32bit = 4byte
		out.println("BYTE=" + Integer.BYTES + "bytes"); // jdk1.8부터 추가..
		out.println("TYPE=" + Integer.TYPE);
	}
}

출력결과

i == i2 ? false
i.equals(i2) ? true
i.compareTo(i2) ? 0
i.toString()=100
MAX_VALUE=2147483647
MIN_VALUE=-2147483648
SIZE=32bits
BYTE=4bytes
TYPE=int

0개의 댓글

관련 채용 정보