• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

More polymophism

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can someone explain why polymorphism isn't obeyed when using private access modifier

Heres my demo program



This program prints A when run. If someMethod were not declared private, then the subclass method executes. Whats the rule here?
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
private members of a class are its sole property and no-one can access it because it's scope is limited to the boundary of the class. Sometimes it is neccessary to preserve certain informations from being accessed outside class for security reasons.. ex: PHI( Protected Health Information) you cannot disclose someone's phi or someone's personal Bank A/C or salary.. these are confidential so keep it private to a class.
 
Arka Guhathakurta
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
private members of a class are its sole property and no-one can access it because it's scope is limited to the boundary of the class. Sometimes it is neccessary to preserve certain informations from being accessed outside class for security reasons.. ex: PHI( Protected Health Information) you cannot disclose someone's phi or someone's personal Bank A/C or salary.. these are confidential so keep it private to a class.
 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are few things to note here. Mainly private methods are not inherited. You are invoking the method "someMethod()" (which is private) from within the class which defined the method (you are not able to do that outside this class). "someMethod()" in class B is not the overriden method in class A but a different method which is defined in class B.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic