aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes method overriding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "method overriding" Watch "method overriding" New topic
Author

method overriding

Venkata Saraswathi
Ranch Hand

Joined: Sep 27, 2008
Posts: 55


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

Joined: Jun 03, 2009
Posts: 9
I think your are right. There is no problem in compilation.
Bob Wheeler
Ranch Hand

Joined: Apr 24, 2009
Posts: 317
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


SCJP 6 - SCJD - SCWCD 5 - SCBCD 5
JavaEnterpriseEditionFaq - TomcatFaq
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14435
    
  23

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Madhu Desai
Ranch Hand

Joined: Jun 14, 2009
Posts: 42
Venkata Saraswathi wrote:


Has the author of this question has clearly mentioned that both classes were created in seperate files? Please check.

Thanks
Preparing for SCJP 6
Bob Wheeler
Ranch Hand

Joined: Apr 24, 2009
Posts: 317
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

Joined: Aug 03, 2008
Posts: 9321
    
  17

What's the visibility of getMessage() in TestOv class, is it accessible in another package??

And please quote proper source...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Madhu Desai
Ranch Hand

Joined: Jun 14, 2009
Posts: 42
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...
 
wood burning stoves
 
subject: method overriding