Calling Subclass Method in Java
- by destructo_gold
Given the following situation (UML below),
If Y has the method:
public void PrintWs();
and X has:
ArrayList <P> myPs = new ArrayList();
Y y = new Y();
Z z = new Z();
myPs.add(y);
myPs.add(z);
How do I loop through each myPs object and call all Ys PrintWs (without using instanceof)?
http://starbucks.mirror.waffleimages.com/files/68/68c26b815e913acd00307bf27bde534c0f1f8bfb.jpg