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())