We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi,
I am using the GI Centre chart library to draw an XY Chart. I have created an object from the XYChart which is a sub-class of the AbstractChart class. I can call various methods from the XYChart class fine in order to modify the object. But I want to call a method from the AbstractChart class (the SetMinBorder method).
I am trying to do it by the below:
XYChart lineChart;
void setup()
{
size(800, 600);
textFont(createFont("Arial", 10), 10);
// Axis formatting and labels.
lineChart.showXAxis(true);
lineChart.showYAxis(true);
lineChart.setMinY(20);
lineChart.setMinX(0);
lineChart.setMaxY(70);
lineChart.setMaxX(current_max_x);
lineChart.setXAxisLabel("Time (mins)");
lineChart.setYAxisLabel("Temperature");
lineChart.setAxisLabelColour(10);
lineChart.setMinBorder(10);
My issue is that I can't call the setMinBorder method; it returns that the method is "not visible". From a fair bit of internet research, given that the two classes are contained with the same package and that the method is inherited by the XYChart class, I'm not sure why. Any help would be much appreciated.
Thanks.
Answers
The method is protected so it is only visible from classes that inherit from this class or classes in the same package. So it is visible to the source code of the XYChart class, but it can not be invoked using an object of type XYChart.
Members which are
protected
can be accessed only by subclasses andpackage
! [-XSince you've already got a XYChart subclass, hack its parent class into submission! o=>
Override anything you want w/ your own version and access level: :ar!
Only the "default" (and of course
public
) access level can access members of the samepackage
.protected
access level only allows subclassing! :-@@GoToLoop
Wrong on both counts - check it out here
Oops! Somehow in my mind I thought both
protected
& package were more restrictive than "default" & subclassing! It turns out thatprotected
is mere 1 step away frompublic
. X_XI've gotta memorize that table better. I knew about that, but failed to carve it in my brain so far! :O)
Since "default" doesn't allow inheritance access, it's almost as "efficient" as
private
! ~:>Easily done :)
I was still programming in C++ when I first started working with Java and I assumed that the access modifiers behaved in exactly the same. It was some time before I learned the truth about Java protected and that was by accident.
Dunno C++ but a few of C. Processing doesn't show much opportunity to train Java access.
And the word
protected
seems more "serious" than package default access! [-(But as said, I've already studied Java access. It's the chosen words for access which led me astray! :-@