Access modifiers show which parts of a class are meant for callers and which are internal.

Access Modifiers

access.ts
class Wallet {
    private cents: number;

    constructor(startingCents: number) {
        this.cents = startingCents;
    }

    deposit(cents: number): void {
        this.cents = this.cents + cents;
    }

    balance(): number {
        return this.cents;
    }
}

const depositCents: number = ;
const wallet: Wallet = new Wallet(1000);
wallet.deposit(depositCents);

console.log(`balance=${wallet.balance()}`);
class Wallet {
    private cents: number;

    constructor(startingCents: number) {
        this.cents = startingCents;
    }

    deposit(cents: number): void {
        this.cents = this.cents + cents;
    }

    balance(): number {
        return this.cents;
    }
}

const depositCents: number = ;
const wallet: Wallet = new Wallet(1000);
wallet.deposit(depositCents);

console.log(`balance=${wallet.balance()}`);
class Wallet {
    private cents: number;

    constructor(startingCents: number) {
        this.cents = startingCents;
    }

    deposit(cents: number): void {
        this.cents = this.cents + cents;
    }

    balance(): number {
        return this.cents;
    }
}

const depositCents: number = ;
const wallet: Wallet = new Wallet(1000);
wallet.deposit(depositCents);

console.log(`balance=${wallet.balance()}`);
private `private` marks a class member that should only be used inside the class.