summaryrefslogtreecommitdiff
path: root/oop/09-polymorphism/CustomerApp.java
diff options
context:
space:
mode:
Diffstat (limited to 'oop/09-polymorphism/CustomerApp.java')
-rw-r--r--oop/09-polymorphism/CustomerApp.java46
1 files changed, 46 insertions, 0 deletions
diff --git a/oop/09-polymorphism/CustomerApp.java b/oop/09-polymorphism/CustomerApp.java
new file mode 100644
index 0000000..79e1c31
--- /dev/null
+++ b/oop/09-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();
+ */
+ }
+}