Sponsored Link •
|
Advertisement
|
Advertisement
|
This page contains an archived post to the Design Forum (formerly called the Flexible Java Forum) made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.
Message:
> Hello please could you clarify on the above. > BR > > I have an abstract base class with two concrete subclasses. > > abstract class Animal ... > > Right, I want to write a method which does something with > > void buy(Cat c) ... > > So far so good. But in my client code, I store references > > Animal animal = new Dog(); > > Now, when I try to call: buy(animal); > > So, my questions are: > > Any help greatly appreciated. > > Cheers, > > Chris You have probably already been helped with this problem, but I would create an empty or abstract method buy(){} in Animal. This allows the instance of Animal to use the cat or dog method of buy.
Replies: |
Sponsored Links
|