• 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
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

Re-Implementation Versus Overriding

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is something straight from the ePractice exam that seemed a bit like a trick question, but let me make sure I've got the idea down right.

In the Heller and Roberts book "Complete Java 2 Study Guide, Fifth Edition" it says that final, when applied to a method, does not allow it to be overridden, so when I came across this question:



I would think that Book would cause a compilation error. However, Page.read () isn't an override, it's a reimplementation. If I removed the 'final' it would then become and override and then it would break. Is that correct?
[ January 25, 2006: Message edited by: Brandon Tom ]
 
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Brandon Tom:

If I removed the 'final' it would then become and override and then it would break. Is that correct?



Even if you remove the final keyword, the methods are private and private methods are not inherited. So there is no question of overriding them.
Hope I didn't confuse you...
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bcos, the method 'read()'is marked as private final in Book class, the page class method 'read()' probably is reimplementation.

if u try removing private in Book class, Page class will not compile as method 'read()' stands final.

public class Book {
final void read() { System.out.print("book "); }
}
 
ven kaar
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bcos, the method 'read()'is marked as private final in Book class, the page class method 'read()' probably is reimplementation.

if u try removing private in Book class, Page class will not compile as method 'read()' stands final.



anyway , i am not sure whether it is reimplementation(first time i am hearing this)
 
Brandon Tom
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see, so it's the 'private' declaration that is the key here, not the word final. I see, thanks for the input.
 
I can't beleive you just said that. Now I need to calm down with this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic