• Post Reply Bookmark Topic Watch Topic
  • New Topic

It possible to hide a property of superclass?  RSS feed

 
D. Formenton
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!