qq_Sweet小情緒_0
2017-06-04 11:53:31
家庭作業(yè)編程11.定義一個class名稱叫Wheel,Wheel含有兩個屬性(實例變量)byte?color;int?size;Wheel含有一個?兩個參數(shù)的構造器,分別給Wheel中的color,size賦值;Wheel中含有一個公共的普通方法,public?void?roll(){ System.out.println("I?am?rolling...");}2.定義一個Car類,Car中含有四個屬性(實例變量)Wheel?wheel1,wheel2,wheel3,wheel4;Car含有一個?四個參數(shù)的構造器,分別給wheel1,wheel2,wheel3,wheel4賦值;Car中含有一個公共的普通方法,public?void?go(){ wheel1.roll(); wheel2.roll(); wheel3.roll(); wheel4.roll();}Car中含有一個main的入口方法,入口方法中實例化Car,并調用Car的go方法?
2 回答
已采納

不換行
TA貢獻7條經(jīng)驗 獲得超2個贊
其實吧,你的答案好像已經(jīng)出來了啊
public class Wheel
{byte?color;
int?size;
public wheel(int size,byte color)
{this.color=color;
this.size=size;}
public?void?roll(){
System.out.println("I?am?rolling...");
}}
文件2
public class car
{private Wheel1,Wheel2,Wheel3,Wheel4;
public car(Wheel one,Wheel two,Wheel three,Wheel four)
{Wheel1=one;
Wheel2=two;
Wheel3=three;
Wheel4=four;}
public?void?go(){
wheel1.roll();
wheel2.roll();
wheel3.roll();
wheel4.roll();
}
public static void main(String args[]){
car one=new car();
one.go();}
}
添加回答
舉報
0/150
提交
取消