implements class typescript code example
Example 1: typescript extend interface
interface Vehicle {
brand: string;
plateNumber: number;
}
interface Car extends Vehicle {}
Example 2: extends vs implements in typescript
class Person {
name: string;
age: number;
walk(): void {
console.log('Walking (person Class)')
}
constructor(name: string, age: number) {
this.name = name;
this.age = age;
}
}
class child extends Person { }
class man implements Person {
name: string;
age: number
constructor(name: string, age: number) {
this.name = name;
this.age = age;
}
walk(): void {
console.log('Walking (man class)')
}
}
(new child('Mike', 12)).walk();
(new man('Tom', 12)).walk();