728x90 java object2 [JAVA] ch05-19. 생성자 4 public class Ex19 { public static void main(String[] args){ Auto auto = new Auto(); Auto auto2 = new Auto(auto); char a = 0; } } class Auto{ String color; String gearType; int door; Auto(){ this("White", "auto", 4); } Auto(Auto auto){ color = auto.color; gearType = auto.gearType; door = auto.door; } Auto(String color, String gearType, int door){ this.color = color; this.gearType = gearType; this.. JAVA/예제 2017. 8. 22. [JAVA] ch05-17. 생성자 2 public class Ex17 { public static void main(String[] args){ Car c1 = new Car(); c1.color = "White"; c1.gearType = "Auto"; c1.door = 4; Car c2 = new Car("Black", "Auto", 2); System.out.printf("c1: %s %s %d\n",c1.color, c1.gearType, c1.door); System.out.printf("c2: %s %s %d",c2.color, c2.gearType, c2.door); } } class Car{ String color; String gearType; int door; Car(){} Car(String c, String g, int.. JAVA/예제 2017. 8. 22. 이전 1 다음 728x90