I am reading about inheritance. I tried to do the example but something is amiss. I wrote every bit of code but a certain method which was suppose to be inherited doesnt show. the method is add(GObject arg)
Here is the code for the class:
package ExistingClasses;
import acm.graphics.*;
public class FilledRect extends GRect {
public FilledRect(double x, double y, double width, double height) {
super(x, y, width, height);
setFilled(true);
}
}
After I wrote the code above I want to use it in other class The code is:
package ExistingClasses;
public class TestFilledRect extends FilledRect {
public void run(){
FilledRect rect = new FilledRect(45, 34, 34, 34);
add(rect);
}
}
The add method does not work. I followed the book's way of doing it. It suppose to have the add method so that anything you drew like an oval, rectangle, line will appear. Please help me.
The add method only works for me when I extend GraphicsProgram class. Please help me. Thanks for all in advance.
The book I am using is The Art and Science of Java pgs 205 - 207