0% found this document useful (0 votes)
5 views1 page

Static Implementation Example

The document outlines the creation of a Bank class with static variables for bank name and account counter, along with a static method to generate unique account numbers. It also describes an Account class that holds account details and utilizes the Bank class to assign account numbers. A TestBankSystem class is included to create multiple accounts and display their details, demonstrating the functionality of the static block and shared bank name.

Uploaded by

ABDUL RAFIO
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

Static Implementation Example

The document outlines the creation of a Bank class with static variables for bank name and account counter, along with a static method to generate unique account numbers. It also describes an Account class that holds account details and utilizes the Bank class to assign account numbers. A TestBankSystem class is included to create multiple accounts and display their details, demonstrating the functionality of the static block and shared bank name.

Uploaded by

ABDUL RAFIO
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

• Create a class named Bank

• Add a static variable bankName (e.g., "National Bank")


• Add another static variable accountCounter initialized to 1000

• Inside the Bank class, add a static block

• Print a welcome message ("Welcome to the Bank System!")


• Print the bank name

• In the Bank class, add a static method generateAccountNumber()

• Increment accountCounter
• Return the new account number

• Create another class named Account

• Instance variables: accountNumber, holderName, balance


• Constructor should:
o Assign holderName and balance
o Call [Link]() to get a unique accountNumber

• In the Account class, add a display() method

• Print account details: accountNumber, holderName, balance, and [Link]

• Create a test class named TestBankSystem with main()

• Create multiple accounts (e.g., Ali, Sara, Ahmed)


• Call display() on each account

• Run the program

• Observe the static block executes once


• Each account gets a unique number
• All accounts share the same bank name

You might also like