-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path20_Inheritance.ts
More file actions
59 lines (49 loc) · 1.26 KB
/
20_Inheritance.ts
File metadata and controls
59 lines (49 loc) · 1.26 KB
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
/*
Inheritance : Reusablity
typescript supports single level, multiple, multilevel inheritance.
Access specifiers are public, private, protected.
Default access specifier is public.
*/
// Declare class Student
class Student
{
// Characteristics
Sname:string;
//constructor
constructor(value:string)
{
this.Sname = value
}
//Behaviour
DisplayS():void
{
console.log("Name of student : "+this.Sname)
}
}
// Inherite Student class
//use keyword extend
class Employee extends Student
{
// Characteristics
Eid : number;
//constructor
constructor(value:number, name:string)
{
super(name); //super keyword
this.Eid = value;
}
//Behaviour
DisplayE():void
{
console.log("ID of Employee : "+this.Eid)
}
}
// Create object of above class
var obj1 = new Employee(11,"Piyush Khairnar");
obj1.DisplayS();
obj1.DisplayE();
// instanceof operator is used to check whether the specific variable is object of class or not
var bret = obj1 instanceof Student; //instanceof
console.log(" obj1 is an instance of Student " +bret);
var bret = obj1 instanceof Employee;
console.log(" obj1 is an instance of Employee " +bret);