如何把数组遍历输出
如何把数组遍历输出
如何把数组遍历输出
2017-04-12
class AutoMobile{
}
class Car extends AutoMobile {
int cup;
String name;
int p;
int ap;
public Car(){
}
public Car(int a,String b,int c,int d){
this.cup=a;
name=b;
p=c;
ap=d;
}
//如下是关键 得加入 这个toString
@Override
public String toString() {
return "Car [cup=" + cup + ", name=" + name + ", p=" + p + ", ap=" + ap + "]";
}
}
main的遍历:
AutoMobile[] message={
new Car(1,"奥迪A4",500,4),
new Car(2,"马自达6",400,4)
};
System.out.println(message.length);
for(AutoMobile t:message){
System.out.println(t);
}
举报