Mid From PDF Power Questions High-Impact Interview Questions

Multi-Threaded Bank System?

public class BankAccount
{
private object _lock = new object();
public decimal Balance { get; private set; }
public void Deposit(decimal amount)
{

lock(_lock)

{
Balance += amount;
}
}
public void Withdraw(decimal amount)
{

lock(_lock)

{
if (Balance >= amount)
Balance -= amount;
}
}
}

Ensures thread safety and prevents financial inconsistency.

More from Career Preparation

All questions for this course
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details