• 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
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Jaworski Java 2 Programmer Exam Quiz

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which are true about overriding
A. The overriding and overridden methods must have the same name, argument list and return type.
B. The overriding method must not limit access more than the overridden method.
C. The overriding method must not throw any exceptions that may not be thrown by the overridden method.
D. The overriding method may not be private.
The answer given are A, B, C and D.
But I thought the overriding method can throw runtime exceptions even though they are not thrown by the overridden method. If I remember correctly, in one other mock exam( I thing it is Marcus Green), it is clearly and correctly said that option C is not true. Any comments from others?.

Thanks
Raj
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Statement C is 100% true. I don't know what this other answer from Marcus or someone else was, but I suspect it was phrased a bit differently. For example, the statement
<blockquote>The overriding method must not throw any exceptions that were not declared by the overridden method.</blockquote>
is false, because you can throw a RuntimeException or Error even if it wasn't declared. But these could have been thrown in the overridden method as well, so statement C above is still true.
[This message has been edited by Jim Yingst (edited July 01, 2000).]
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Can someone explain why statement D is true?
Thanks very much!
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
statement D is true bcoz:
1. the private methods of a (base) class are not visible in other class ( the derived sub classes) .. so when u have a class which has the same name, signature and return as a private method of the base class, you arent really overriding it. For the compiler, u are creating an entirely new method.
a class can only override a method which is coderanch, default or protected in the base class.
2. as the access modifier of an overriding method cannot be more restrictive than the overridden method, u can't have a 'private' method overriding a public/default/protected method.
cheers,
vivek
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic