0% found this document useful (0 votes)
3 views3 pages

Encapsulation

Encapsulation is a key principle of object-oriented programming that combines data and methods into a single unit called a class, enhancing code organization and data protection. The document includes a code example of a BankAccount class demonstrating encapsulation through private data members and public methods. This structure allows for controlled access and flexibility in managing the account's data.

Uploaded by

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

Encapsulation

Encapsulation is a key principle of object-oriented programming that combines data and methods into a single unit called a class, enhancing code organization and data protection. The document includes a code example of a BankAccount class demonstrating encapsulation through private data members and public methods. This structure allows for controlled access and flexibility in managing the account's data.

Uploaded by

aarchie077
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Encapsulation

Encapsulation is a fundamental pillar of object-


oriented programming (OOP). It's a powerful tool for
structuring and organizing code, improving
maintainability, and protecting data integrity.
>> It's a fundamental concept of object-oriented
programming (OOP) that bundles data and the
methods that operate on that data within a single
unit, known as a class.
>> This allows for better organization, control over
access, and increased flexibility in code design.
CODE
#include <iostream>
using namespace std;

class BankAccount {
OUTPU
T
private:
int accountNumber;
double balance;
public:
Account Number: 123
BankAccount(int accNum, double bal) : accountNumber(accNum), balance(bal) {}
int getAccountNumber() { return accountNumber; } Initial Balance: 1000
double getBalance() { return balance; } Updated Balance: 150
void setBalance(double bal) { balance = bal; }
};

int main() {
BankAccount account(12345, 1000.0);
cout << "Account Number: " << account.getAccountNumber() << endl;
cout << "Initial Balance: " << account.getBalance() << endl;
account.setBalance(1500.0);
cout << "Updated Balance: " << account.getBalance() << endl;
return 0;
}

You might also like