Search Results

Search found 1 results on 1 pages for 'vtanathip'.

Page 1/1 | 1 

  • I'm confused about Polymorphism

    - by Vtanathip
    I'm know polymorphism rule that we can send it via parameter like this code interface Animal { void whoAmI(); } class A implements Animal{ @Override public void whoAmI() { // TODO Auto-generated method stub System.out.println("A"); } } class B implements Animal{ @Override public void whoAmI() { // TODO Auto-generated method stub System.out.println("B"); } } class RuntimePolymorphismDemo { public void WhoRU(List t){ System.out.println(t.getClass()); } public static void main(String[] args) { A a = new A(); B b = new B(); RuntimePolymorphismDemo rp = new RuntimePolymorphismDemo(); rp.WhoRU(a); rp.WhoRU(b); } } but List<Example> examples = new ArrayList<Example>(); This code,I'm don't understand why we must use List. why we can't use like this? ArrayList<Example> examples = new ArrayList<Example>(); Because when we use List we can't use method that only have in ArrayList class like trimToSize() and How I know when to use or not use?

    Read the article

1