1 package LHB.inherit;
2
3 public class Electricityfees
4 {
5 private int lastmonth,thismonth;/*上月电表读数,本月电表读数*/
6 public Electricityfees()
7 {
8
9 }
10 public Electricityfees(int lastmonth,int thismonth)
11 {
12 this.lastmonth=lastmonth;
13 this.thismonth=thismonth;
14 }
15 public int getLastmonth()
16 {
17 return lastmonth;
18 }
19
20 public void setLastmonth(int lastmonth)
21 {
22 this.lastmonth = lastmonth;
23 }
24
25 public int getThismonth()
26 {
27 return thismonth;
28 }
29
30 public void setThismonth(int thismonth)
31 {
32 this.thismonth = thismonth;
33 }
34 public void print()
35 {
36 System.out.print("上月电表读数为:"+lastmonth+" ");
37 System.out.println("这个月电表读数为:"+thismonth+" ");
38 }
39 }
1 package LHB.inherit;
2
3 public class TestElectricity
4 {
5
6 public static void main(String[] args)
7 { double x;
8 Electricityfees p=new Electricityfees();
9 p.setLastmonth(1000);
10 p.setThismonth(1200);
11 x=p.getThismonth()*1.2;
12 System.out.println("本月电费为:"+x);
13 Electricityfees q=new Electricityfees(1200,1450);
14 q.setThismonth(1500);
15 x=q.getThismonth()*1.2;
16 System.out.println("本月电费为:"+x);
17 }
18
19 }