• 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
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Wrong answer in SCJA Certification Guide

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear ranchers,

Today I noticed in the Certification book an error in Question 13 Page 333, it says that options (c) and (d) are correct, while option (c) is not correct because its more restrictive "like option (a)".

I have no idea if there was previous disscussion regarding this issue, but anyhow i noticed it while reading the book.

Any comments about this issue?

Thank you.
 
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the question?
 
Hussam Odeh
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Which of the following pieces of code, placed on line xxx, would allow this class to successfully compile?

a) private String doIt() {return null;}
b) Object doIt(int i) {return null;}
c) Object doIt() {return null;}
d) public String doIt() {return null;}

Book's answer is "(c) and (d)", but actually (c) is not correct because its more restrictive.
 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm,

so when you do this:



it works fine. Otherwise it won't work.
 
Hussam Odeh
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The key point here is that when you declare a method inside an interface, it should be ALWAYS "public abstract" and when you declare a variable inside an interface, it should be ALWAYS "public static final", that means when you override any method from an interface, your overriding method should be public, otherwise it will not work because it will be more restrictive.
 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hussam Odeh wrote:The key point here is that when you declare a method inside an interface, it should be ALWAYS "public abstract" and when you declare a variable inside an interface, it should be ALWAYS "public static final", that means when you override any method from an interface, your overriding method should be public, otherwise it will not work because it will be more restrictive.



True. A overriding method couldn't be more restrictive than the original method defined somewhere higher in the hierarchy, though it's return type could be a sub-type of the return type of the original method.

So in this case only
public String doIt() {return null;}

will work.
 
Hussam Odeh
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Larry Olson wrote: though it's return type could be a sub-type of the return type of the original method.



About the return type, what you said is true ONLY if we were talking about Java 5 or above, otherwise its not allowed.
 
Larry Olson
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for pointing that out. I wasn't aware of that since I was looking into 1.5+. Is it important to understand how 1.5+ is different from the previous versions if one is preparing for SCJP 1.6? Is that a worthwhile exercise?
 
Hussam Odeh
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Larry Olson wrote:Thanks for pointing that out. I wasn't aware of that since I was looking into 1.5+. Is it important to understand how 1.5+ is different from the previous versions if one is preparing for SCJP 1.6? Is that a worthwhile exercise?



I dont think it's necessary for the exam, but it's good to know about it.
 
Larry Olson
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a basic question. Does SCJP exam include questions about Designing Graphical User Interfaces, you know GUI classes like Buttons, frames, layout managers, Swing components etc. etc.

Looking at the Sun SCJP objectives at http://www.sun.com/training/catalog/courses/CX-310-065.xml,
I don't seem to find any references to GUI classes at all. I am surprised. OR am I mis-reading something ?

Thanks.
 
Hussam Odeh
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Larry,

No its not included in the SCJP exam, and you can see the differences between SCJP 5 and SCJP 6 in this url:

http://faq.javaranch.com/java/ScjpFaq#16diff15
 
Good heavens! What have you done! Here, try to fix it with this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic