export class User { private name: string; constructor(name: string, private email: string) { this.name = name; this.email = email; } getInfo() { return `${this.name} (${this.email})`; } } const alice = new User('Alice', 'alice@mail.com'); console.log(alice.getInfo()); export class Admin extends User { constructor(name: string, email: string, public role: string) { super(name, email); } override getInfo(): string { return super.getInfo() + ', ' + this.role; } } const bob = new Admin('Bob', 'bob@mail.com', 'admin'); console.log(bob.getInfo()); console.log(bob.role); class MyClass { public publicProperty: string = 'Public'; private privateProperty: string = 'Private'; protected protectedProperty: string = 'Proctected'; getPrivatePropertyValue(): string { return this.privateProperty; } } class MySubClass extends MyClass { public getProtectedPropertyValue(): string { return this.protectedProperty; } } const myclass = new MyClass(); console.log(myclass.publicProperty); console.log(myclass.getPrivatePropertyValue()); const mysubclass = new MySubClass(); console.log(mysubclass.getProtectedPropertyValue()); export class MathUtil { static PI: number = 3.14159; test = 'demo'; static circleArea(radius: number): number { return this.PI * radius * radius; } } const mathUtil = new MathUtil(); mathUtil.test; export class Person { private _age: number; constructor(age: number) { this._age = age; } get age(): number { return this._age; } set age(value: number) { if (value < 0) { throw new Error('Alter kann nicht negativ sein!'); } this._age = value; } } const person = new Person(42); console.log(person.age); person.age = 43; console.log(person.age); export abstract class Animal { constructor(public name: string) {} abstract makeSound(): void; } class Dog extends Animal { override makeSound(): void { console.log('Wuff wuff'); } } const dog = new Dog('Bello'); dog.makeSound();