随笔 - 322  文章 - 0  评论 - 4  阅读 - 77146

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 }
复制代码

 

posted on   Bytezero!  阅读(77)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示