• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

S&B Practice Exams, Test 1, # 14 question

 
Kent Hilton
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm brand new to JavaRanch, but I've found a lot of useful info here prior to joining. I'm preparing for the OCPJP/SCJP 6.0 exam, and after going completely through the S&B Java 6 Study Guide(over several months), I just started with the Practice Exams book. I just finished Assessment Test 1, and got stumped on an inheritance issue by the last question:



This code will not compile because MyPancake.doStuff() must be marked public. I can't figure out why that would be. 1) The <default> access modifier is not more restrictive than the inherited method, and 2) the MyPancake.doStuff() method is being called from its own class, and certainly not from some class in a different package. Any help here?

Thanks
Kent
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kent,
Welcome to CodeRanch!

In an interface, a method is public whether you specify the moderator or not. In a class, not specifying a modifier means default. Which is more restrictive than the public interface version.

Note that I've added code tags to your post to make the code easier to read.
 
Kent Hilton
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne,

Thanks so much for the prompt reply! And thank you for fixing the code so it is more readable. In the future I will know to use code tags.

I went back through the study guide, and there it is on page 20, barely into Chapter 1:

"All interface methods are implicitly public and abstract."

I knew this at one point and must have simply forgotten. That is the answer I needed.

Thanks again!
Kent
 
Bert Bates
author
Sheriff
Posts: 8900
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In an interface, a method is public whether you specify the moderator or not. In a class, not specifying a modifier means default. Which is more restrictive than the public interface version.


Also true whether you specify the modifier or not
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic