목록JAVA/chapter20_api (13)
WON.dev
package org.joonzis.ex; // 반드시 Cloneable 인터페이스를 구현하자 // 복제 가능한 Person 클래스로 만들기 위함 class Person implements Cloneable{ private String name; private int age; public Person(String name, int age) { this.name = name; this.age = age; } @Override public String toString() { return "이름 : " + name + ", 나이 : " + age; } @Override public Object clone() {// protected -> public으로 변경 // Object obj = super.clone(..
package org.joonzis.ex; class Computer{ private String model; private int price; public Computer(String model, int price) { this.model = model; this.price = price; } @Override public String toString() { return "모델 : " + model + ", 가격 : " + price; } @Override public boolean equals(Object obj) { if(obj != null && obj instanceof Computer) { Computer another = (Computer)obj; return model.equals(anot..
package org.joonzis.ex; class Sample{ @Override public String toString() { return "SAMPLE"; } } public class Ex01_Object { public static void main(String[] args) { Object object = new Object(); System.out.println(object); object = 10; System.out.println(object); object = "Hello"; System.out.println(object); // Object object = new Sample();// 업캐스팅 object = new Sample(); // 객체만 출력 하더라도 자동으로 toStri..