cannot reference publicationDate before supertype constructor has been called

735 views Asked by At

Im having trouble with this book class extending from a publication abstract class which extends from a publishable interface class. however when i try to compile it bring up the error message "cannot reference publicationDate before supertype constructor has been called"

This is my Book class code:

public abstract class Book extends Publication
{
   /**
    * Set the attributes inherited from the publication class 
    */
   public Book (String publicationDateIn, boolean subscriptionIn, String subscriptionLengthIn, int pageNumbIn,
                String publisherNameIn, String publicationTitleIn, float priceIn, String publicationTypeIn, String issnNumbIn
                , int authorNumbIn)
   {
        super (publicationDate, subscription, pageNumb, publisherName, publicationTitle, price, publicationType, subscriptionLength, authorNumb, issnNumb);
   }
}
1

There are 1 answers

2
Sotirios Delimanolis On

I'm assuming your Publication class has a publicationDate field (and all the other ones you have there). You can't reference that field in a sub type constructor until the super constructor has been invoked.

Did you mean to have

super (publicationDateIn, subscriptionIn, pageNumbIn, publisherNameIn, publicationTitleIn, priceIn, publicationTypeIn, subscriptionLengthIn, authorNumbIn, issnNumbIn);

? In other words, you weren't using your constructor parameters, you were using the parent class' fields.