public static void main(String[] args) {
Car matiz = new Car();
matiz.setModel("matiz");
matiz.setDoorCount(4);
Engine mEngine = new Engine();
mEngine.setType("A");
mEngine.setCc(1000);
matiz.setEngine(mEngine);
matiz.print();
}
}
----------------------------------------------------
public class Car {
private String model;
private int doorCount;
/****engine****/
private Engine engine;
/**************/
public void setData(String model, int doorCount, Engine engine){
this.model=model;
this.doorCount=doorCount;
this.engine=engine;
}
public void print(){
System.out.println("모델:"+this.model);
System.out.println("문수:"+this.doorCount);
/*
System.out.println("엔진타입:"+this.engine.getType());
System.out.println("엔진배기량:"+this.engine.getCc());
*/
engine.print();
}
/*
public String getInfo(){
return ""+model+"\t"+doorCount+"\t"+"engine";
}
*/
public void setEngine(Engine engine) {
this.engine=engine;
}
public Engine getEngine() {
return this.engine;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public int getDoorCount() {
return doorCount;
}
public void setDoorCount(int doorCount) {
this.doorCount = doorCount;
}
}
--------------------------------------------------------
public class Engine {
private String type;//엔진의 타입
private int cc; //엔진의 배기량
public void print(){
System.out.println(this.type);
System.out.println(this.cc);
/*
* String getInfo = this.getInfo();
*
*System.out.println(getInfo);
*/
}
/*
public String getInfo() {
return type+"\t"+cc;
}
*/
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public int getCc() {
return cc;
}
public void setCc(int cc) {
this.cc = cc;
}
}
배열에 들어갔나 보네. 배열의 개념은 모든 언어 공통:)
답글삭제잘하고 있구만~~^^
답글삭제ㅋㅋ 당신도.
삭제