static 变量使用

来源:互联网 发布:数据元和元数据 编辑:程序博客网 时间:2024/06/12 21:22
package hello;public class stu {int age;double fee;char name;static int totalfee; public stu(int age,char name,double fee){this.age=age;this.name=name;totalfee+=fee;}public static int getfee(){return totalfee;}public static void main(String args[]) {stu stu1=new stu(22,'a',120);stu stu2=new stu(19,'b',220);System.out.println(stu.getfee());}}