HCI 20130501
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package cartest2;
class Car {
int fuelecon;
String Diesel;
String Hybrid;
String gasoline;
String fuelType;
String color; // 색상
String gearType; // 변속기 종류 - auto(자동), manual(수동)
int door; // 문의 개수
////////////////////////////////////////////////////////////////////////
Car(String color, String gearType, int door, int fuelecon, String fuelType) {
this.color = color;
this.gearType = gearType;
this.door = door;
this.fuelecon = fuelecon;
this.fuelType = fuelType;
}
Car() {
this("white", "matic", 6, 20, "gasoline");
}
Car(int door, int fuelecon){
this("white","auto",door,fuelecon,"가솔린");
}
}
class CarTest2 {
public static void main(String[] args) {
Car c1 = new Car();
System.out.println("c1의 color=" + c1.color + ", gearType=" + c1.gearType + ", door=" + c1.door+ ", fuelecon=" + c1.fuelecon+ ", fueletype=" + c1.fuelType);
}
}
///////////////////////////////////////////////////////////////////////
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package constructortest;
class Data1 {
int value;
}
class Data2 {
int value;
Data2(int x) { // 매개변수가 있는 생성자.
value = x;
}
Data2(){}
}
class ConstructorTest {
public static void main(String[] args) {
Data1 d1 = new Data1();
Data2 d2 = new Data2(); // compile error발생
}
}
//////////////////////////////////////////////////////////////////////
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package constructortest;
class Data1 {
int value;
}
class Data2 {
int value;
Data2(int x) { // 매개변수가 있는 생성자.
value = x;
}
}
class ConstructorTest {
public static void main(String[] args) {
Data1 d1 = new Data1();
Data2 d2 = new Data2(10); // compile error발생
}
}
////////////////////////////////////////////////////////////////////