-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinheritance of number.js
More file actions
45 lines (42 loc) · 1.25 KB
/
inheritance of number.js
File metadata and controls
45 lines (42 loc) · 1.25 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
const logger = require('./logger.js')
class Test{
constructor(numberOne,numberTwo){
this.numberOne=numberOne;
this.numberTwo=numberTwo;
}
multiplication (numberOne,numberTwo)
{
return numberOne*numberTwo;
}
division(numberOne,numberTwo)
{
try {
if (numberTwo===0) {
let errormsg ="Cant divide by 0";
throw Error(errormsg);
logger.info(errormsg)
}
else return numberOne/numberTwo;
} catch (error) {
logger.info(`${error}`);
}
}
subtraction (numberOne,numberTwo)
{
return numberOne-numberTwo;
}
};
class Add extends Test{
/*constructor(numberOne,numberTwo){
super(numberOne,numberTwo)
}*/
add(a,b){
return a+b;
}
}
var res=new Add(4,3);
console.log(res.add(4,3)); // priority is given to local methods
console.log(res.multiplication(5,10)); // child class inherits parent class
console.log(res.division(10,2)); // child class inherits parent class
logger.info(res.division(10,3));
console.log(res.subtraction(3,0)); // defined in parent class and called from child class object which inherit Parent class