Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Person {
- protected name: string;
- protected constructor(theName: string) {
- this.name = theName;
- }
- }
- class Employee extends Person {
- private department: string;
- constructor(name: string, department: string) {
- super(name);
- this.department = department;
- }
- public getElevatorPitch() {
- return `Hello, my name is ${this.name} and I work in ${this.department}.`;
- }
- }
- let howard = new Employee('Howard', 'Sales');
- let john = new Person('John');
- // constructor of class 'Person' is protected and only accessible within the class declaration.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement