Reputation: 941
I need to get a field of an object instantiated in a superclass. The problem is that I need to get it from a subclass two levels deep from the superclass, that is, I am in the class SingleChart
which extends SingleTable
, which itself extendsTemplateReport
class. TemplateReport
instantiates the private Report
object. Report
has public getters and setters. I want to retrieve the height
field of Report
.
Is there a way of doing this directly from SingleChart
to TemplateReport
?
Upvotes: 0
Views: 121
Reputation: 746
Private instance variables are inherited by the sub-classes.
So if TemplateReport makes a Report object, and Report has getters and setters. You are able to get the Report object from any subclass by call the getter and then asking for the value you need.
Upvotes: 1
Reputation: 2939
TemplateReport would need a public getReport() method so you can access the report instance from the subclass. If you don't want to allow access to that instance then you could have specific methods that allow access:
public int getReportHeight() {
return report.height;
}
Upvotes: 0