package oop.Demon11;
public class Students {
public static void main(String[] args) {
//创建两个学生对象
Stu tom = new Stu("tom");
tom.payFee(10000);
Stu jack = new Stu("jack");
jack.payFee(1200);
Stu.showFee();
System.out.println(myTools.method(23,12));
}
}
//开发自己的工具类时,可以将方法做成静态的,方便调用
class myTools{
public static double method(double n1,double n2){
return n1+n2;
}
}
class Stu{
private String name;
private static double fee = 0;
public Stu(String name) {
this.name = name;
}
public static void payFee(double fee){
Stu.fee+=fee;
}
public static void showFee(){
System.out.println("总学费为:"+Stu.fee);
}
}
image.png
网友评论