I'm writing a program in Java (11 I think).
I have an abstract class:
public abstract class Homework
{
// instance variables - replace the example below with your own
private int pages;
private String type;
/**
* Constructor for objects of class Homework
*/
public Homework()
{
// initialise instance variables
pages = 0;
type = "none";
}
public void setPages(int pages)
{
this.pages = pages;
}
public int getPages()
{
return pages;
}
public abstract void createAssignment(int pages);
}
And a subclass:
public class Trigonometry extends Homework
{
/**
* Constructor for objects of class Trigonometry
*/
public Trigonometry()
{
super();
}
public void createAssignment(int pages)
{
this.pages = pages;
type = "Trigonometry";
}
}
I get an error at this.pages
and type
in the createAssignment()
method.
pages has private access in Homework
type has private access in Homework
Shouldn't Trigonometry
inherit pages
and type
from its parent class? What can I do to fix this?