-
Notifications
You must be signed in to change notification settings - Fork 1
/
classes.ts
47 lines (33 loc) · 843 Bytes
/
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
class Product
{
protected name :string;
protected price : number;
constructor(name :string, price : number) {
this.name = name;
this.price = price;
}
print():void {
console.log(this.name);
console.log(this.price);
}
}
var per1 = new Product("iPhone7 Plus", 70000);
per1.print();
class TaxProduct extends Product
{
protected tax : number;
constructor(name :string, price : number, tax:number) {
super(name,price);
this.tax = tax;
}
print():void {
super.print();
console.log(this.tax);
}
getNetPrice(): number {
return this.price + this.price * this.tax / 100;
}
}
var tp = new TaxProduct("Dell Laptop",65000,12);
tp.print();
console.log("Net Price : " + tp.getNetPrice());