-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathISAExample.java
More file actions
59 lines (53 loc) · 1.12 KB
/
ISAExample.java
File metadata and controls
59 lines (53 loc) · 1.12 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
class Account //extends Object
{
void withDraw(){
System.out.println("Account Class WithDraw");
}
void deposit(){
System.out.println("Account Class Deposit");
}
void roi(){
System.out.println("Sample ROI");
}
}
class CurrentAccount extends Account
{
void odLimit(){
System.out.println("OverDraft Limit Feature");
}
//@Override
void roi(){
System.out.println("Current Account ROI is 7%");
}
}
class SavingAccount extends Account{
void roi(){
System.out.println("Saving Account ROI is 4%");
}
}
public class ISAExample {
/*
* Polymorphic Method
*/
static void caller(Account account){
account.withDraw();
account.deposit();
account.roi();
if(account instanceof CurrentAccount){
CurrentAccount ca = (CurrentAccount) account; //Downcasting
ca.odLimit();
}
System.out.println("*************************");
}
public static void main(String[] args) {
caller(new SavingAccount());
caller(new CurrentAccount());
caller(new Account());
// Upcasting
/*Account account = new SavingAccount();
account.withDraw();
account.deposit();
account.roi();*/
//account.odLimit();
}
}