File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes S&B Practice Exams, Test 1, # 14 question 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 "S&B Practice Exams, Test 1, # 14 question" Watch "S&B Practice Exams, Test 1, # 14 question" New topic
Author

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

Kent Hilton
Greenhorn

Joined: Apr 10, 2011
Posts: 2
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

Joined: May 26, 2003
Posts: 31076
    
233

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Kent Hilton
Greenhorn

Joined: Apr 10, 2011
Posts: 2
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

Joined: Oct 14, 2002
Posts: 8883
    
    5
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


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: S&B Practice Exams, Test 1, # 14 question