728x90
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 d){
color = c;
gearType = g;
door = d;
}
}
728x90
'JAVA > 예제' 카테고리의 다른 글
[JAVA] ch05-19. 생성자 4 (0) | 2017.08.22 |
---|---|
[JAVA] ch05-18. 생성자 3 (0) | 2017.08.22 |
[JAVA] ch05-16. 생성자 (0) | 2017.08.22 |
[JAVA] ch05-15. Method (메서드) (0) | 2017.08.22 |
[JAVA] ch05-14. Static method (스태틱 메서드) 2 (0) | 2017.08.22 |
댓글