某种服饰,包括名称和价格两个属性,要求设计服饰类,然后在主类中申明一个包含三个对象的数组,分别给三个对象赋值,最后输出数组中的所有值
3条回答 默认 最新
CSDN专家-showbo 2022-07-04 14:42关注class t{ public static void main(String[]args){ Clothes []cs=new Clothes[3]; cs[0]=new Clothes("服饰1",111.11); cs[1]=new Clothes("服饰2",222.22); cs[2]=new Clothes("服饰3",333.33); cs[0].print(); cs[1].print(); cs[2].print(); } } class Clothes { String name; double price; public Clothes(String name,double price){ this.name = name; this.price=price; } public void setPrice(double price){ this.price = price; } public void setName(String name){ this.name = name; } public void print(){ System.out.println("名称:"+ name +"\t价格:" + price ); } }本回答被题主选为最佳回答 , 对您是否有帮助呢?评论 打赏 举报 编辑记录解决 1无用