This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes concept of method overriding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "concept of method overriding" Watch "concept of method overriding" New topic

concept of method overriding

Sandeep Tyagi

Joined: Mar 07, 2006
Posts: 3
why we can't use narrowing method in sub class on the case of method overriding
Thanks in advance

with Regards
Sandeep Tyagi
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11164

i think it is because of polymorphism...

say you have a ClassA, with a public doSomething() method.

now, ClassB extends ClassA. say you could make B's doSomething() private.

now you make a collection of ClassA. you get a ClassB object, which you can put into the collection, since a ClassB is a ClassA.

now you iterate through the collection, calling doSomething() on every object. when you get to that ClassB, you're gonna have a problem...

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
I agree. Here's the link:
subject: concept of method overriding
Similar Threads
HELP: doPost without throw
Nikos Blog Overloading Question 58
in Overriding
Problem with mock exam question
Trying to access a servlet on button click