Skip to content

Commit 7252fd5

Browse files
authored
Create 13Encapsulation.js
1 parent 829366c commit 7252fd5

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

OOPS/13Encapsulation.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
class balanceacc{
2+
name;
3+
accountnumber;
4+
#balance=0; //private variable
5+
constructor(name,balance=0){
6+
this.name=name;
7+
this.accountnumber=Date.now();
8+
this.#balance=balance;
9+
}
10+
deposit(amount){
11+
this.#balance+=amount;
12+
}
13+
withdraw(amount){
14+
this.#balance-=amount;
15+
}
16+
17+
//SETTER
18+
set balance(amount){
19+
if(isNaN(amount)){
20+
throw new Error('ENTER A VALID NUMBER');
21+
}
22+
this.#balance=amount;
23+
}
24+
25+
//GETTER
26+
get balance(){
27+
return this.#balance;
28+
}
29+
}
30+
class savingacc extends balanceacc{
31+
transactionlimit=2000;
32+
constructor(name,balance=0){
33+
super(name,balance);
34+
}
35+
}
36+
class curracc extends balanceacc{
37+
transactionlimit=5000;
38+
constructor(name,balance=0){
39+
super(name,balance);
40+
}
41+
display(amount){
42+
console.log('withdrawn amount is '+amount);
43+
}
44+
}
45+
let a=new curracc('swapno',5000);
46+
console.log(a);
47+
a.display(10000);
48+
let b=new savingacc('shubho',10000);
49+
console.log(b);

0 commit comments

Comments
 (0)