0

Can somebody explain me this??

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()); } } }

11th Oct 2020, 5:15 AM
Yuexue
Yuexue - avatar
3 Answers
+ 2
In class BankAccount you have an instance variable balance and few methods. 1) When Deposit() method is called, your balance value will increase by n. 2) When Withdraw() method is called, your balance value will reduce by n. 3) When GetBalance() method is called, it will return your balance. In Program class inside Main() method you are creating an instance of BankAccount, or you can call it an object. You are then calling all the methods of that class which will perform respective operations.
11th Oct 2020, 6:01 AM
Avinesh
Avinesh - avatar
+ 2
It means that the method returns a value when called. When you say b.GetBalance() it will give you the balance.
11th Oct 2020, 7:31 AM
Avinesh
Avinesh - avatar
0
What does return means?
11th Oct 2020, 6:55 AM
Yuexue
Yuexue - avatar