Iam writing a simple Java program for an assignment,which implements a library system using inheritance.I have a class named Entry and two others who extend it (book and journal).
Everything works fine.
Now i must create a class which will test the whole program.This class should use an array to store the elements (books OR journals which i want to add in the system).I don’t know how many elements i will add but i must declare an array for them (either my entry will be book,or journal).My question is:This array should be an Entry array (as i suppose) and if yes,if for example i want to add a book the extra elements that Book has where will be stored?
Thank you in advance.
Yes you should add to an
Entryarray. You can addBookinstance to theEntryarray since it is extendingEntry. To access the properties or methods ofBookafter getting it fromEntryarray, you have to cast it toBook.