Hiya,
Im learning java and am new to the concept of abstract classes. I thought I understood it when I heard it, but I still dont understand something.
If I have a method Info() (say in class Chocolate, that returns the information about the chocolate bar, but is overridden in classes (say Yorkie and Mars which extend chocolate, for which the method Info() is slightly different), then I think i am supposed to use an abstract class, as Chocolate's Info() method has no useful body. However, how then and I supposed to use chocolate, in say Shop class, if I cannot implement it?
Chocolate contains a methods that is overridden in Mars and Yorkie (Info()), and the constructor which is used as super() in Mars and Yorkie.
I never have a Chocolate object, only Mars or Yorkie objects, but the methods are shared (polymorphism), and they are both Chocolate .
I am asking as the hand in date for this is monday, and we are supposed to use these concepts, but I am not sure if I should be using an abstract class for chocolate (or interfaces?). I need the Shop class use the Methods in Chocolate, but only the overridden version in Mars and Yorkie, and get a list of the Mars and Yorkie objects (as Chocolate objects). Should chocolate abstract, and if so how does Shop use it if i cannot implement it? How do you actually use an abstract class? Please reply ASAP!
Thanks!