• 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
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

please explain this

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

then write method of process is called why?
please explain
payal
[This message has been edited by payal sharma (edited July 27, 2001).]
 
Ranch Hand
Posts: 464
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Payal,
Thats what private's do!! They are soo picky
Well let see,
In the eariler case you had modifiers for both the write() methods as friendly/coderanch. So during Dynamic Invocation, write()from subclass gets called satisfying the polymorphic effect.
But
When you make the parent write() private, dynamic invocation
fails because privates are very personal, and they would not share it with anybody else, even to their subclasses and these two write()methods become independent of each other. As as result, write() from parent gets called, since
you had used parent's class reference in the first place
To put it in a nut shell:
private methods behaviour is closely similar to static when it comes to overriding.
Thankyou
 
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good explaination private meths do behave as static .
If u want more info there is a good example at www.absolutejava.com
 
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just be careful on 2 points :

  1. private methods are not overriden
  2. the method of the current object is invoked.

  3. Hope this helps,
    Sandeep
    SCJP2, OCSD(Oracle JDeveloper), OCED(Oracle Internet Platform)
 
We begin by testing your absorbancy by exposing you to this tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic