-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimalinhert.js
95 lines (86 loc) · 1.67 KB
/
animalinhert.js
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
class Animal{
eat(){
console.log("I can eat")
}
walk(){
console.log("I am walk")
}
}
class Dog extends Animal{
foodtype(){
console.log("I am vegetarian")
}
}
class Tiger extends Animal{
}
const a=new Animal
a.eat()
a.walk()
// second program in inheritance using super keyword
class Person{
constructor(name,age,city,mbno){
this.name=name
this.age=age
this.city=city
this.mbno=mbno
}
display(){
console.log(this.name)
console.log(this.age)
console.log(this.city)
console.log(this.mbno)
}
}
class Employee extends Person{
constructor(name,age,city,mbno,salary){
super(name,age,city,mbno)// super for code reuse
this.salary=salary
}
display1(){
super.display()
console.log(this.salary)
}
}
const p1= new Person("raju",20,"pune",12344)
const e1= new Employee("ramu",21,"mumbai",1234566,400000)
p1.display()
e1.display1()
// method overriding
class Perent{
gold(){
console.log("I have gold")
}
}
class Son extends Perent{
gold()
{
console.log("I cannot take gold now")
}
}
const p1s= new Perent()
const p1son= new Son()
p1s.gold()
p1son.gold()
// method overloading not possible but last one function is execute every time
function add(a,b){
console.log(a+b)
}
function add(a,b,c){
console.log(a+b+c)
}
function add(a,b,c,d){
console.log(a+b+c+d)
}
add(10,20)
add(10,20,30)
add(10,20,30,40)
// synchronous program
console.log("hii")
console.log("Hello")
console.log("welcome")
// asynchronous program
console.log("hii")
setTimeout(()=>{
console.log("welcome")
},3000)
console.log("hello")