-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClass_implement.ts
More file actions
43 lines (35 loc) · 937 Bytes
/
Copy pathClass_implement.ts
File metadata and controls
43 lines (35 loc) · 937 Bytes
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
// defining interface for class
interface Person
{
firstName: string;
lastName: string;
age: number;
FullName();
GetAge();
}
// implementing the interface
class Employee implements Person
{
firstName: string;
lastName: string;
age:number;
FullName()
{
return this.firstName + ' ' + this.lastName;
}
GetAge()
{
return this.age;
}
constructor(firstN: string, lastN: string, getAge: number)
{
this.firstName = firstN;
this.lastName = lastN;
this.age = getAge;
}
}
// using the class that implements interface
let myEmployee = new Employee('Vishal', 'Pandey', 25);
let fullName = myEmployee.FullName();
let Age = myEmployee.GetAge();
console.log("Name of Person: " +fullName + '\nAge: ' + Age);