반응형
toString 예제
class Car{
String model;
String company;
public Car(String model, String company) {
super();
this.model = model;
this.company = company;
}
@Override
public String toString() {
return "Car [model=" + model + ", company=" + company + "]";
}
}
public class ToStringTest {
public static void main(String[] args) {
Car c1 = new Car("K7", "현대차");
Car c2 = new Car("아반테", "기아차");
System.out.println(c1);
System.out.println(c2);
}
}
toString API
getClass().getName() + '@' + Integer.toHexString(hashCode())
반응형
'콩's EDUCATION > 콩's JAVA_RUN' 카테고리의 다른 글
String 메소드 활용 (0) | 2014.05.19 |
---|---|
Clone (0) | 2014.05.19 |
Java 문제 5 (0) | 2014.05.16 |
사용자 정의 예외 만들기 (0) | 2014.05.16 |
throws 처리 (0) | 2014.05.16 |