Java static 关键字的使用 小练习

 1 package com.bytezreo.statictest2;
 2 
 3 /**
 4  * 
 5  * @Description  static 关键字的使用 小练习
 6  * @author Bytezero·zhenglei!        Email:420498246@qq.com
 7  * @version
 8  * @date 上午9:34:02
 9  * @     
10  *
11  */
12 public class AccountTest 
13 {
14     public static void main(String[] args) {
15         
16         Account acct1 = new Account();
17         Account acct2 = new Account("123456" ,2000);
18         Account.setInterestRate(0.012);
19         Account.setMinMoney(100);
20         
21         System.out.println(acct1);
22         System.out.println(acct2);
23         
24         System.out.println(acct1.getInterestRate());
25         System.out.println(acct1.getMinMoney());
26         System.out.println(acct2.getMinMoney());
27         
28     }
29 }
 1 package com.bytezreo.statictest2;
 2 
 3 public class Account 
 4 {
 5       private int id;
 6       private String pwd = "000000";
 7       private double balance;
 8       
 9       private static double interestRate; 
10       private static double minMoney = 1.0;
11       
12       private static int init = 1001;  //用于自动生成 账户
13       
14       public Account()
15       {
16            id = init++;
17       }
18       
19       public Account(String pwd,double banlance)
20       {
21           id = init++;
22           this.pwd = pwd;
23           this.balance = banlance;
24       }
25 
26     public String getPwd() {
27         return pwd;
28     }
29 
30     public void setPwd(String pwd) {
31         this.pwd = pwd;
32     }
33 
34     public static double getInterestRate() {
35         return interestRate;
36     }
37 
38     public static void setInterestRate(double interestRate) {
39         Account.interestRate = interestRate;
40     }
41 
42     public static double getMinMoney() {
43         return minMoney;
44     }
45 
46     public static void setMinMoney(double minMoney) {
47         Account.minMoney = minMoney;
48     }
49 
50     public int getId() {
51         return id;
52     }
53 
54     public double getBalance() {
55         return balance;
56     }
57 
58     @Override
59     public String toString() {
60         return "Account [id=" + id + ", pwd=" + pwd + ", balance=" + balance + "]";
61     }
62       
63       
64       
65 }

Java    static 关键字的使用 小练习

 

上一篇:十分钟学会Lua五:面向对象基础


下一篇:Mybatis缓存