본문 바로가기

콩's EDUCATION/콩's JAVA_RUN

toString

반응형

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


 

 

 

 

ToStringTest.java

 

반응형

'콩'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

⚠️ 광고 차단 프로그램 감지

애드블록, 유니콘 등 광고 차단 확장 프로그램을 해제하거나
화이트리스트에 추가해주세요.