文章标题

封装
class Hua
{
private String name; //花的属性
private String color;
private String location;
public void setname(String name){ // 设置花对象的属性
this.name=name;
}
public void setcolor(String color){
this.color=color;
}
public void setlocation(String location){
this.location=location;
}
public String gatname(){ //访问器获得花属性
return name;
}
public String gatcolor(){
return color;
}
public String gatlocation(){
return location;
}
private void print(){
System.out.println(“这就是”+name);
}
public String tostring(){
String information=(“花名;”+name+”;”+” “+”花的颜色;”+color1+”;”+”“+”花的出产地;”+location);
print();
return information;
}

}

class Huatext
{
public static void main(String args){
flower f1=new flower(); //创建三个对象f1,f2,f3
flower f2=new flower();
flower f3=new flower();
f1.setname(“牡丹”);
f1.setcolor(“红色”);
f1.setlocation(“云南”);
f2.setname(“玫瑰”);
f2.setcolor(“黄色”);
f2.setlocation(“北京”);
f3.setname(“月季”);
f3.setcolor(“蓝色”);
f3.setlocation(“上海”);
//输出相应的信息
System.out.println(f1.tostring());
System.out.println(f2.tostring());
System.out.println(f3.tostring());
}
}
请各位大神们多多指教!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值