+ 1
Can you explain me the step by step process in this?
Encapsulation using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class BankAccount { private double balance=0; public void Deposit(double n) { balance += n; } public void Withdraw(double n) { balance -= n; } public double GetBalance() { return balance; } } class Program { static void Main(string[] args) { BankAccount b = new BankAccount(); b.Deposit(199); b.Withdraw(42); Console.WriteLine(b.GetBalance()); } } }
1 Odpowiedź
+ 1
You create a b object from the class BankAccount.Then you can access the two public function Deposit() and Withdraw() to modify the private variable balance value.Finally you display the final value of balance 167.