Forums Register Login

It possible to hide a property of superclass?

+Pie Number of slices to send: Send
Hi,

If I extends a class A to Class B, in B I can see all public getters and setters (and public methods).

My question is: it possible to avoid to show some (not all) of public getters and setter (and public methods) of superclass when I use the subclass?

Thank you

+Pie Number of slices to send: Send
 

D. Formenton wrote:
If I extends a class A to Class B, in B I can see all public getters and setters (and public methods).

My question is: it possible to avoid to show some (not all) of public getters and setter (and public methods) of superclass when I use the subclass?




Of course, this is not recommended, as a subclass IS-A superclass, and must work in place of a superclass. However, if you really want to do this, one option could be to "disable" the public methods by overriding them -- to throw an exception. The overridden method is still accessable to the subclass, as it can use the super keyword.

Henry
+Pie Number of slices to send: Send
 

D. Formenton wrote:My question is: it possible to avoid to show some (not all) of public getters and setter (and public methods) of superclass when I use the subclass?


What Henry said. However, it is possible to hide/remove methods by wrapping rather than subclassing, particularly if the "superclass" implements an interface.

Winston
Always look on the bright side of life. At least this ad is really tiny:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 902 times.
Similar Threads
abstract methods
Confused about overloading and overriding
protected constructors
about protected modifier
Calling the paint() method of superclass()
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 22:50:41.