-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoverRide.java
More file actions
46 lines (40 loc) · 961 Bytes
/
overRide.java
File metadata and controls
46 lines (40 loc) · 961 Bytes
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
class BankAccount{
public int deposit, withdraw;
public BankAccount(int deposit, int withdraw){
this.deposit=deposit;
this.withdraw=withdraw;
}
public int deposit(){
return deposit;
}
public int withdrawMoney(){
return withdraw;
}
}
class SavingsAccount extends BankAccount{
public SavingsAccount(int deposit, int withdraw){
super(deposit, withdraw);
}
@Override
public int withdrawMoney(){
if(deposit<100){
System.out.println("Low balance");
return deposit-withdraw;
}
else{
return withdraw;
}
}
}
public class Main{
public static void main(String args[]){
BankAccount my= new BankAccount(50, 100);
BankAccount my2= new BankAccount(50, 0);
my.withdrawMoney();
my2.withdrawMoney();
SavingsAccount my3= new SavingsAccount(50, 100);
my3.withdrawMoney();
SavingsAccount my4= new SavingsAccount(100, 100);
my4.withdrawMoney();
}
}