复制代码
- //:Car.java
- //Compositionwithpublicobjects
- classEngine{
- publicvoidstart(){}
- publicvoidrev(){}
- publicvoidstop(){}
- }
- classWheel{
- publicvoidinflate(intpsi){}
- }
- classWindow{
- publicvoidrollup(){}
- publicvoidrolldown(){}
- }
- classDoor{
- publicWindowwindow=newWindow();
- publicvoidopen(){}
- publicvoidclose(){}
- }
- publicclassCar{
- publicEngineengine=newEngine();
- publicWheel[]wheel=newWheel[4];
- publicDoorleft=newDoor(),
- right=newDoor();//2-door
- Car(){
- for(inti=0;i<4;i++)
- wheel[i]=newWheel();
- }
- publicstaticvoidmain(String[]args){
- Carcar=newCar();
- car.left.window.rollup();
- car.wheel[0].inflate(72);
- }
- }///:~
欢迎光临 仓酷云 (http://ckuyun.com/) | Powered by Discuz! X3.2 |