public class fulei { public fulei() { System.out.println("欢迎使用海尔"); } public String Pinpai; public String Xinghao; public fulei(String pinpai, String xinghao) { this.Pinpai = pinpai; this.Xinghao = xinghao; System.out.println(Pinpai+"饮水机 "+"型号为"+Xinghao); } int t = 0; public void reshui(int 时间) { t = 时间; if(t > 15&&t<20) { System.out.println("保温"); } else { System.out.println("加热"); } } public void xiaodu(int 时间1) { t = 时间1; if(t >= 20) { System.out.println("消毒"); } } }
public class zilei1 extends fulei { public zilei1 (String Pinpai, String Xinghao) { super (Pinpai, Xinghao); } public zilei1() { String Pinpai = "美的"; String Xinghao = "HB350"; System.out.println("我是"+Pinpai+Xinghao); } int t; public void xiaodu(int t) { if(t > 65) { System.out.println("正在消毒"); } } }
public static void main(String[] args) { // TODO Auto-generated method stub fulei ysj1 = new fulei(); fulei ysj = new fulei("Haier", "GB125"); ysj.reshui(6); ysj.xiaodu(70); ysj.reshui(16);
zilei1 ysj2 = new zilei1(); ysj2.xiaodu(70); //向上转型调用方法 fulei ysj3 = new zilei1(); ysj3.xiaodu(80); } }