-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4_classes.ts
49 lines (40 loc) · 1.06 KB
/
4_classes.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
abstract class UserAccount {
public name: string;
protected age: number;
constructor(name: string, age: number) {
this.name = name;
this.age = age;
}
logDetails(): void {
console.log(`The player ${this.name} is ${this.age} years old.`);
}
}
class CharAccount extends UserAccount {
private nickname: string;
readonly level: number;
constructor(name: string, age: number, nickname: string, level: number) {
super(name, age);
this.nickname = nickname;
this.level = level;
}
get getAge() {
return this.age
}
set setAge(age: number) {
this.age = age
}
logCharDetails(): void {
console.log(`The player ${this.name} is ${this.age} and has the char ${this.nickname} at level ${this.level}`)
}
}
// const rafs = new UserAccount('Rafael', 27);
// console.log(rafs);
// console.log(rafs.age);
// rafs.logDetails();
const wilian = new CharAccount('Willian', 30, 'wilmaster', 100);
console.log(wilian);
console.log(wilian.level);
wilian.logDetails();
wilian.logCharDetails();
wilian.setAge = 8000;
console.log(wilian.getAge);