-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathISA.java
More file actions
83 lines (81 loc) · 2.14 KB
/
ISA.java
File metadata and controls
83 lines (81 loc) · 2.14 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
* What is Overriding?
* When you do Inheritance , so child recieve parent things.
* so child has 2 options
* a) Use same.
* b) do the override
* Overriding only happen when there is IS A.
* Overriding hide the parent version.
* Overriding method signature should be same as parent.
* Overriding means parent version is outdated. that's why we override in child
*/
abstract class Account{
int id;
String name;
double balance;
Account(){
System.out.println("Account class Cons");
}
@Deprecated
void deposit(){
System.out.println("Account Deposit...");
}
void withDraw(){
System.out.println("Account WithDraw");
}
void checkBalance(){
System.out.println("Account CheckBalance....");
}
abstract void roi(); // Bodyless method
// @Deprecated
// void roi(){
// System.out.println("Generic ROI 2%");
// }
}
class SavingAccount extends Account{
SavingAccount(){
super();
}
@Override
void roi(){
//super.roi();
System.out.println("ROI for SA 4%");
}
}
class CurrentAccount extends Account{
@Override
void roi(){
System.out.println("ROI for CA 5%");
}
void noLimit(){
System.out.println("CA No Limit of Trans");
}
}
public class ISA {
static void call(Account account){
account.deposit();
account.withDraw();
account.checkBalance();
account.roi();
if(account instanceof CurrentAccount){
((CurrentAccount)account).noLimit(); // Downcasting
}
}
public static void main(String[] args) {
call(new SavingAccount());
call(new CurrentAccount());
// Account a = new Account();
// Account account = new SavingAccount(); // Upcasting
// //SavingAccount sa = new SavingAccount();
// account.deposit();
// account.withDraw();
// account.checkBalance();
// account.roi();
// account = new CurrentAccount();
// account.deposit();
// account.withDraw();
// account.checkBalance();
// account.roi();
// account.noLimit();
}
}