-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankAccountSystem.java
More file actions
59 lines (46 loc) · 1.78 KB
/
Copy pathBankAccountSystem.java
File metadata and controls
59 lines (46 loc) · 1.78 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
class BankAccount {
// Static variable
public static String bankName = "Javabeans Bank";
// Static method for total accounts
private static int totalAccounts = 0;
public static int getTotalAccounts() {
return totalAccounts;
}
// Instance variables
private String accountHolderName;
private final int accountNumber;
// Constructor using 'this' for clarity
public BankAccount(String accountHolderName, int accountNumber) {
this.accountHolderName = accountHolderName;
this.accountNumber = accountNumber;
totalAccounts++;
}
// Getter methods
public String getAccountHolderName() {
return accountHolderName;
}
public int getAccountNumber() {
return accountNumber;
}
// Instanceof demonstration in main
}
public class BankAccountSystem {
public static void main(String[] args) {
// Testing BankAccount class
BankAccount acc1 = new BankAccount("Manan Gupta", 101);
BankAccount acc2 = new BankAccount("Raj Singh", 102);
System.out.println("Bank Name: " + BankAccount.bankName);
System.out.println("Account Holder: " + acc1.getAccountHolderName() + ", Account Number: " + acc1.getAccountNumber());
System.out.println("Account Holder: " + acc2.getAccountHolderName() + ", Account Number: " + acc2.getAccountNumber());
System.out.println("Total Accounts: " + BankAccount.getTotalAccounts());
if (acc1 instanceof BankAccount) {
System.out.println("Account 1 is an instance of BankAccount.");
}
}
}
////Sample Output
//Bank Name: Javabeans Bank
//Account Holder: Manan Gupta, Account Number: 101
//Account Holder: Raj Singh, Account Number: 102
//Total Accounts: 2
//Account 1 is an instance of BankAccount.