Hey there, I'm trying to call a method in a subclass, savingsaccount. when i call this method, it involves a field called balance in the superclass, called account. When i try to involve this field in the method, it says that the field is private and cannot be accessed. Is there a way around this with keeping the field private? We are not supposed to change the access type.
Kind regards and much appreciation for any help
解决方案
No. The superclass should provide appropriate methods to access the field's value appropriately, possibly performing validation.
The whole point of making a field private is to stop other classes from accessing it directly - instead they have to go through the methods you expose.