728x90 자바 생성자4 [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-18. 생성자 3 public class Ex18 { public static void main(String[] args){ Vehicle v1 = new Vehicle(); Vehicle v2 = new Vehicle("blue"); System.out.printf("v1: %s %s %d\n", v1.color, v1.gearType, v1.door); System.out.printf("v2: %s %s %d",v2.color, v2.gearType, v2.door); } } class Vehicle{ String color; String gearType; int door; //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. [JAVA] ch05-16. 생성자 public class Ex16 { Data1 d1 = new Data1(); Data2 d2 = new Data2(); Data2 d3 = new Data2(3); } class Data1{ int value; } class Data2{ int value; Data2(){ value = 100; } Data2(int x){ value = x; } } JAVA/예제 2017. 8. 22. 이전 1 다음 728x90