public, private, and protected Modifiers
Control access to class members with modifiers.
Welcome
TypeScript access modifiers control the visibility of class members. They help enforce encapsulation and prevent unintended usage.
public: Accessible Everywhere
public is the default. Public members are accessible from anywhere — inside the class, subclasses, and external code.
class Car {
public brand: string;
constructor(brand: string) { this.brand = brand; }
}
const c = new Car('Toyota');
console.log(c.brand); // OKAll lessons in this course
- TypeScript Classes and Constructors
- public, private, and protected Modifiers
- readonly Properties and Parameter Properties
- Implementing Interfaces with Classes