p193 .2
父类
package shuibei;
public class shuibei {
public shuibei()
{
}
public shuibei(String pinpai,String rongliang)
{
this.pinpai = pinpai;
this.rongliang = rongliang;
}
//品牌
private String pinpai;
public String getPinpai()
{
return pinpai ;
}
//容量
private String rongliang;
public String getRongliang()
{
return rongliang;
}
private int shuiliang = 40;
public void setShuiliang(int shuiliang)
{
if(shuiliang < 0)
{
System.out.println("水量不能为负");
}
else if(shuiliang > 500)
{
this.shuiliang = 500;
System.out.println("灌满了,水量为:" + 500);
}
else
{
this.shuiliang = shuiliang;
System.out.println("水量为 : " + shuiliang);
}
}
//获取水量
public int getShuiliang()
{
return shuiliang ;
}
//吹瓶
public static void chuiping()
{
System.out.println("吹瓶一次要喝水500");
}
}
子类
package shuibei;
public class suliaoshuibei extends shuibei {
public suliaoshuibei(String pinpai,String rongliang)
{
super(pinpai, rongliang);
}
public suliaoshuibei()
{
}
//外表花纹
public void waibiaohw(String huawen)
{
System.out.println("我的塑料水杯外表花纹是:" + huawen);
}
public static void chuiping()
{
System.out.println("塑料杯吹瓶要喝水350" );
}
}