File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed
Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change 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 ) ;
You can’t perform that action at this time.
0 commit comments