• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

It possible to hide a property of superclass?

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
author
Posts: 23959
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic