diff options
| author | Kamal Wickramanayake <kamal@inbox.lk> | 2026-02-22 19:43:58 +0530 |
|---|---|---|
| committer | Kamal Wickramanayake <kamal@inbox.lk> | 2026-02-22 19:43:58 +0530 |
| commit | baaba4a281b7d54e6b5d7767989c303b854b6932 (patch) | |
| tree | 16201b64e9c8f20d7fa394c715f4ca5df51e9e08 /oop/05-polymorphism/CustomerApp.java | |
| parent | ae4cf7c9f0a0b90d02166b43402e67b7d4ad4dca (diff) | |
Directory rename
Diffstat (limited to 'oop/05-polymorphism/CustomerApp.java')
| -rw-r--r-- | oop/05-polymorphism/CustomerApp.java | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/oop/05-polymorphism/CustomerApp.java b/oop/05-polymorphism/CustomerApp.java new file mode 100644 index 0000000..79e1c31 --- /dev/null +++ b/oop/05-polymorphism/CustomerApp.java @@ -0,0 +1,46 @@ +import java.util.ArrayList; +import java.util.Date; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +public class CustomerApp { + + /** + * @param args + */ + public static void main(String[] args) { + List list = new LinkedList(); + + Customer c = new Customer(1, "Kamal", "Nugegoda", "123456", "654321"); + list.add(c); + + c = new Customer(2, "Nimal", "Colombo", "2234343", "2343433"); + list.add(c); + + c = new PremiumCustomer(1, "Sunil", "Kohuwala", "23443434", "9888234", + "a", "Give him whatever he ask"); + list.add(c); + + list.add(new Date()); + + Iterator itr = list.iterator(); + + CustomerDetailsFormatter formatter = new CustomerDetailsFormatter(); + + while (itr.hasNext()) { + Customer customer = (Customer) itr.next(); // Convert "java.lang.Object" to "Customer" + String formattedString = formatter.getFormattedDescription(customer); + System.out.println(formattedString); + } + + /* + Account a1 = new SavingsAccount(); // Coercion (implicit conversion) + a1.accountClassMethod(); + + Account a1 = someMethod(); + SavingsAccount sa = (SavingsAccount) a1; // Down casting + sa.savingsAccountClassMethod(); + */ + } +} |
