-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpractice_set_11.js
57 lines (49 loc) · 1.05 KB
/
practice_set_11.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
// 1)
class Complex{
constructor(real,imaginary){
this.real = real;
this.imaginary = imaginary;
}
add(num){
this.real += num.real;
this.imaginary += num.imaginary;
}
set real(newReal){
this._real = newReal;
}
get real(){
return this._real;
}
set imaginary(newImaginary){
this._imaginary = newImaginary;
}
get imaginary(){
return this._imaginary;
}
}
let c1 = new Complex(4,7);
let c2 = new Complex(2,3);
console.log(`c1 = ${c1.real}+${c1.imaginary}i`);
c1.add(c2);
console.log(`c1 = ${c1.real}+${c1.imaginary}i`);
c1.real = 10;
c1.imaginary = 20;
console.log(c1.real);
console.log(c1.imaginary);
// 2)
// class Human{
// constructor(name){
// this.name = name;
// }
// walk(){
// console.log("Human "+this.name+" is walking!");
// }
// }
// class Student extends Human{
// walk(){
// super.walk()
// console.log("Student "+this.name+" is walking!");
// }
// }
// let o = new Student("Abhi");
// o.walk()