• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

method overriding

 
Venkata Saraswathi
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


It is mock exam question. In that answer is l#1 will not compile.
But I didnt find any issue with that line.

can anyone give an explanation why the answer is like that?
 
Prabhu Manickam
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think your are right. There is no problem in compilation.
 
Bob Wheeler
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Edit: 5m late
I also know this answer from ExamLab (no compiler error there). Maybe the superclass method getMessage had a private modifier.
I'm not sure, but that doesn't make a difference. The subclass can't see the superclass method, so it doesn't
override that method. So no problem.
The output is: <msg>test</msg>

cheers
Bob
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15219
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Venkata Saraswathi wrote:It is mock exam question.

When you copy a question from a book, mock exam or other source, here on JavaRanch we require that you quote your sources. So, please tell us exactly where you copied this from. Just saying "a mock exam" is not good enough.
 
Madhu Desai
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Venkata Saraswathi wrote:


Has the author of this question has clearly mentioned that both classes were created in seperate files? Please check.
 
Bob Wheeler
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Madhu Desai wrote:
Has the author of this question has clearly mentioned that both classes were created in seperate files? Please check.

Normally this kind of code shows the line numbers (number 1 indicating a new file),
And if I remember right, this is also true for this question. Otherwise this would be a very easy question.
So to answer your question. No, I don't assume the author clearly mentioned that explicitly.

cheers
Bob
 
Ankit Garg
Sheriff
Posts: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the visibility of getMessage() in TestOv class, is it accessible in another package??

And please quote proper source...
 
Madhu Desai
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Venkata Saraswathi

Often people make typo mistakes and get into compiler error, which otherwise would have been a perfect running program.

But in this case it seems, after studying java so much and taking mock tests many times, it might be possible that -even though there was a deliberate error in code, instinctively, you have corrected the error while typing unknowingly...

please re-check the code again...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic