• 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

overriding

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While overriding wat are the rules for access specifiers-watz more restricitve and less restrictive

can a static variable and instance variable be in same name
 
Ranch Hand
Posts: 360
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public, protected, default, private

less restrictive.....more restrictive

:-)

for the second question...you don't have compiler?
 
Ranch Hand
Posts: 257
Hibernate Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Exceptions should not be more super type but may be sub type of overriding method.
Access specifiers may be less restrictive.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hiiiii,

Coming to overridding concept.....When we override any parent class method inside child class,the child class cannot restrict the access specifier of parent class inside child class.

suppose parent class method have a "public" method,when child class method overrides that method it cannot make that method as private/default/protected.

Similarly if parent class method has "protected" method,then child class cannot make its method as a private/default.

When it comes to Exception handling....
(1)the child class method can throw the same Exception or subclass of that Exception which the perent class method is throwing.....only if the parent class method is throwing "compile time/Checked Exception."

(2)The child class method can throw Exception other than what the parent class method is throwing only if the parent class method is throwing RunTimeExceptions........Read alll these point carefully.i hope everybody can understand,bye.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another way of looking at the rules about new Exceptions or access modifiers; no method of a subclass may make any more demands on its clients than its superclass counterpart.
You can't insist the client handle any more exceptions and can't insist on any more restrictive access. Otherwise you couldn't use polymorphism.
 
So it takes a day for light to pass through this glass? So this was yesterday's tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic