Encapsulation (computer programming): Difference between revisions

Content deleted Content added
No edit summary
No edit summary
Line 19:
Below is an example in [[C Sharp (programming language)|C#]] that shows how access to a data field can be protected through the use of a <code>private</code> keyword:
<source lang="csharp">
namespace Encapsulation
{
class Program {
{
public class Account {
{
private decimal accountBalance = 500.00m;
public decimal CheckBalance() {
{
return accountBalance;
}
}
 
static void Main() {
{
Account myAccount = new Account();
decimal myBalance = myAccount.CheckBalance();
Line 36 ⟶ 41:
* "CheckBalance" method provided by the "Account" class
* but it cannot manipulate the value of "accountBalance" */
}
}
}