TypeScript Classes
class BankAccount {
public owner: string;
private balance: number;
protected accountType: string;
constructor(owner: string, balance: number) {
this.owner = owner;
this.balance = balance;
this.accountType = "standard";
}
public deposit(amount: number): void {
this.balance += amount;
}
public getBalance(): number {
return this.balance;
}
}
const acc = new BankAccount("Ravi", 100);
acc.deposit(50);
console.log(acc.getBalance());
// acc.balance; // Error: 'balance' is private