-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.ts
104 lines (89 loc) · 1.7 KB
/
class.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
interface IPrint {
print(): void;
id: number;
}
class A {
print() {
console.log('A');
}
}
class B {
print() {
console.log('B');
}
}
var a = new A();
a.print();
var b = new B();
b.print();
class C implements IPrint {
id = 10;
readonly name : string = 'anil';
constructor(_name?: string) {
// this.name = _name;
console.log(this.name);
}
print() {
console.log(this.id);
console.log('C');
}
setReadOnly(_name: string) {
// this.name = _name;
console.log(_name);
}
}
var c = new C('vikram');
c.print();
c.setReadOnly('hello');
class xy {
x: number = 10;
y?: number = 20;
constructor(_x: number, _y?: number) {
this.x = _x;
this.y = _y;
console.log(this.x, this.y);
}
getValue() {
console.log('Hello World');
}
getAnotherValueUsingSuper(value:number) {
console.log(value);
}
}
interface xyz extends xy {
z:number;
}
// let point: xyz = {x:1, y:2, z:3};
// console.log(point);
class P extends xy {
constructor(x: number, y?: number) {
super(x, y);
}
getNewValue(){
super.getAnotherValueUsingSuper(13);
}
}
let p = new P(10, 10);
p.getValue();
p.getAnotherValueUsingSuper(12);
p.getNewValue();
class Q extends P {
}
let q = new Q( 20, 20);
q.getNewValue();
class FA {
public id: number;
getProperties() : string {
return `id: ${this.id}`;
}
}
class FB extends FA {
public name: string;
getProperties(): string {
return `${super.getProperties()}` + ` name: ${this.name}`;
}
}
let fb = new FB();
fb.id = 1;
fb.name = 'hello';
console.log(fb.getProperties());