• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

final and overriding

 
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator




output:
this program compilies fine


where as i was expecting a compiler error.can anyone explain me
that inspite of final keyword in the overridden method this is working fine??
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A method declared as final cannot be overridden. But in your case the method overridden in the base class is NOT final.
So, its legal.
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should consider three things:

1. Access Modifier ( which you did't restricted) rather you made open (protected to public
2. Return type: you did't change
3. Exception which you don't have
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
first you have to consider about these things
overriding methods should have the wider access range

in the base class you are using the protected and in the sub class method you are using the public which was correct.

overriding methods must return the same argument which was correct.

in this case you are overriding the base class method which was not mark as final.
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic