Both Vector and ArrayList are implementing the List interface. But you can't assign a class of type Vector to ArrayList. its basic OO rule. Lets take in this way, CLASS B AND CLASS C IMPLEMENTS INTERFACE A.
A Object = new B(); ok
A Object1 =new C(); ok
but B object=new C(); Not OK
you can assign all its subclasses to super interface but not sub class to subclass.
When you use style 1), you are free to change it to use an ArrayList, LinkedList or some other List implementation, and can be sure that it will still compile. That is, it decouples your code from a specific List implementation and thereby increases its flexibility.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
pLease let me know how can change the style 1 ) to linkedList implementation from ArrayList as Ilja Preuss said
I think you misinterpreted what Ilja said... he was referring to decoupling, which allows you to write code that doesn't depend on the type of the object. He wasn't saying that it was possible to cast one type to another.
You have a code that takes a list and only works with the list interface. It doesn't cast that list back to a vector or an arraylist -- it merely works with the list. Then...
You can use that same method with an ArrayList, or a LinkedList, and it should work. The method only cares about the List contract, it doesn't care about the actual implementation.