-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path21_Interface.ts
44 lines (38 loc) · 1.1 KB
/
21_Interface.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
/*
Interface :
Interfaces define properties, methods, and events, which are the members of the interface.
Interfaces contain only the declaration of the members.
It is the responsibility of the deriving class to define the members.
It often helps in providing a standard structure that the deriving classes would follow.
*/
// Declare interface
interface Student
{
name:string,
college:string,
fun:()=>string
}
// Implement the above interface
var obj1:Student =
{
name:"Piyush Khairnar",
college:"Pune University",
fun: ():string =>{return "Welcome to Marvellous Infosystems"}
}
// Display contents of object
console.log("Students Object obj1:")
console.log(obj1.name)
console.log(obj1.college)
console.log(obj1.fun())
// Implement the above interface
var obj2:Student =
{
name:"Aman Patel",
college:"Sinhgad",
fun: ():string =>{return "Marvellous : Admission Confirmed"}
}
// Display contents of object
console.log("Students Object obj2")
console.log(obj2.name)
console.log(obj2.college)
console.log(obj2.fun())