Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Is it not a bug on 111 K&B book ?

 
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On page no 104 it is written that

The overriding method can throw narrower or fewer exceptions. Just because an overridden method
"takes risks" doesn't mean that the overriding subclass' exception takes the same risks. Bottom line:
an overriding method doesn't have to declare any exceptions that it will never throw, regardless of
what the overridden method declares.


But on page no 111, in the given table


it is written that
Overridden method can reduce or eliminate Exceptions.Must not throw new or broader checked exceptions.can be less restrictive

class Super
{
public void go() { } \\ According to me it is overridden method
}
class New extends Super
{
public void go() { } \\ and it is overriding method
}
[ May 04, 2008: Message edited by: sachin verma ]
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't see a contradiction here. Which part are you questioning?
 
sachin verma
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
K&B book page no 111
by Dreamtech press for Indian sub-continent only
A table is given
with the heading "Difference between overloaded and Overridden method"
and in the overridden method column see what is written there !
 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's in the caption of the table which shows what happens when a method is overloaded and/or overridden. So you can read it as an overriding method can reduce or eliminate.
 
marc weber
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't have the Dreamtech edition, but the Osborne (McGraw Hill) edition shows what you've indicated in your original post. With respect to exceptions, an overridden method...

Can reduce or eliminate. Must not throw new or broader checked exceptions.


(The part about "can be less restrictive" is in the row beneath that, referring to access instead of exceptions.)

Again, I don't see a contradiction. Which part are you questioning?
 
sachin verma
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

originally posted by Irina Goble:

So you can read it as an overriding method can reduce or eliminate.



You got it.Is it not wrong to use that term (overridden method) for two different purpose.

I KNOW WHAT THE AUTHOR IS REFERRING TO.BUT SHE USED THE SAME TERM FOR TWO
DIFFERENT PURPOSES.
[ May 04, 2008: Message edited by: sachin verma ]
 
marc weber
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, wait... Are you questioning the use of "overridden" instead of "overridding"? If so, I see what you are saying.

But in this context, I would interpret "overridden" as describing the overall relationship. That is, method x, which appears in both the superclass and the subclass, is overridden. I would not interpret "overridden" as specifically referring to either one of these implementations (i.e., in the parent or subclass).

Does that help?
 
sachin verma
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes it is right and I knew it too

But why it depends on interpretation.It should be very clear(i think) by the term used itself.
I know what the author want to say there.But As I instantly and accidentally interpreted in a wrong way.I think someone else can do it as well
[ May 04, 2008: Message edited by: sachin verma ]
 
sachin verma
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

originally posted by marc weber

That is, method x, which appears in both the superclass and the subclass, is overridden.



But the row now 3(must not make more restrictive) is itself refering to a specific implementation that is used in the sub class
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic