Compiling errata for K&B, SCJP 6
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
My output was "4 6" - which is not a choice in the book.
go() method listed b2, b1 out of order...so, book choice of "6 4" is good answer.
-
2 -
-
Number of slices to send:Optional 'thank-you' note:
-
-
"Finally, you need to know that the abstract modifier can never be combined
with the static modifier."
on
page 45
Static nested classes can be abstract ,so it is not entirely true.
It is under the topic Non access modifiers for members so it's right , but this statement can be a bit misleading.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Frankly, I don't know whether inclusion of proper "import" statements/packages/classes only applies when the code contains the class definition, i.e. public class Animal { }, but given the code as is, it would not compile because of a missing "import java.util.*" statement.
--------------------
Chapter 7, Self-Test, Question 7 (answered on page 653-654): although the answer is "B", the output is partially correct. When a PriorityQueue is empty and peek() is called, it returns "null". Therefore, the output should also contain "null".
The correct answer is (B) 2 2 3 4 null
--------------------
Chapter 7, Self-Test, Question 13: at no point in the chapter SortedMap.firstKey() was mentioned or said to be required to be on the exam. Nonetheless, the question relies on it for the answer. Please clarify whether this method and others in SortedMap/SortedSet , that are not mentioned in the book, are going to be on the test.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
B is meant to be the answer, i.e.
but I get a compilation error :
The type List is not generic; it cannot be parameterized with arguments <Integer>
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Martin Leon wrote:Chapter 10 Self Test, Question 2, page 811, 812
My book has a "." after the "A" as part of the command line that is invoked. None of the answers have a ".", so none of them are correct.
Try it:
java _ - A .
You are wrong Martin Leon when you compile and run the above code it prints A. i.e it prints the Letter 'A' with a dot(.) Try once again
Always believe in yourself
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
6. Given:
1. public class Electronic implements Device { public void doIt() { } }
2.
3. abstract class Phone1 extends Electronic { }
4.
5. abstract class Phone2 extends Electronic { public void doIt(int x) { } }
6.
7. class Phone3 extends Electronic implements Device { public void doStuff() { } }
8.
9. interface Device { public void doIt(); }
What is the result? (Choose all that apply.)
A. Compilation succeeds
B. Compilation fails with an error on line 1
C. Compilation fails with an error on line 3
D. Compilation fails with an error on line 5
E. Compilation fails with an error on line 7
F. Compilation fails with an error on line 9
Answer:
A is correct; all of these are legal declarations.
B, C, D, E, and F are incorrect based on the above information. (Objective 1.2)
The answer given (A. Compilation succeeds) seems incorrect. If the Device interface contains the method public void doIt(), then all classes implementing that interface should implement that method. However, the class Phone 3 implements the Device interface but only implements a doStuff() method. This would cause a compile error due to a mistake on line 7. Answer E should be the correct answer in that case.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Chris Devine wrote:In the Chapter 1 Self-test, question 6:
The answer given (A. Compilation succeeds) seems incorrect. If the Device interface contains the method public void doIt(), then all classes implementing that interface should implement that method. However, the class Phone 3 implements the Device interface but only implements a doStuff() method. This would cause a compile error due to a mistake on line 7. Answer E should be the correct answer in that case.
Hi Chris,
The answer in the book is correct.
Note that "Phone3 extends Electronic" and that "Electronic implements Device { public void doIt() { } }"
Hence, Phone3 inherits the "public void doIt() { }" implementation from Electronic.
Aside, there's no need for Phone3 to explicitly state it implements Device, since Phone3 already inherits that interface from Electronic.
Regards,
Al
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Alan Cowap wrote:
Chris Devine wrote:In the Chapter 1 Self-test, question 6:
The answer given (A. Compilation succeeds) seems incorrect. If the Device interface contains the method public void doIt(), then all classes implementing that interface should implement that method. However, the class Phone 3 implements the Device interface but only implements a doStuff() method. This would cause a compile error due to a mistake on line 7. Answer E should be the correct answer in that case.
Hi Chris,
The answer in the book is correct.
Note that "Phone3 extends Electronic" and that "Electronic implements Device { public void doIt() { } }"
Hence, Phone3 inherits the "public void doIt() { }" implementation from Electronic.
Aside, there's no need for Phone3 to explicitly state it implements Device, since Phone3 already inherits that interface from Electronic.
Regards,
Al
Thanks, Al. I see that now. One my biggest difficulties (being new to Java and coding in general) is being able to see when and how things work even if they violate good programming practices and conventions. Having a class implement an interface that its superclass already implements appears to be one of those cases where just because it's legal doesn't mean it's right.
All the best,
Chris
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Answer:
C,D, and F are correct.
F is wrong !
What is wrong on the enum on line 10, compilation succeeds.
-
1 -
-
Number of slices to send:Optional 'thank-you' note:
-
-
Francky Boy wrote:SELF TEST Page 82, question 7.
Answer:
C,D, and F are correct.
F is wrong !
What is wrong on the enum on line 10, compilation succeeds.
In J2SE version 6, F won't compile:
"The member enum Traffic can only be defined inside a top-level class or interface"
- but it's defined within a method, hence the compiler error.
You could check that you've typed the code correctly, and that you're using the correct compiler (version 6).
Regards,
Al
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
In J2SE version 6, F won't compile:
"The member enum Traffic can only be defined inside a top-level class or interface"
- but it's defined within a method, hence the compiler error.
You could check that you've typed the code correctly, and that you're using the correct compiler (version 6).
Regards,
Al
You're right ! When I try that example under Eclipse with compiler version 6 , the enum line wasn't red !
Thanks and Regards
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Thank you.
Never mind, the key word to watch for was "before use".
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
currently reads:
....that the PlayingPiece class inherits the generic display() method...
maybe should read:
...that the PlayerPiece class inherits the generic displayShape() method...
There are other references to the display() method
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
System.out.println(s1 + " " + s2);
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Jon Frowd wrote:In the question posed on page 433, aren't 9 objects created? Isn't the space character on the last line also a String object?
System.out.println(s1 + " " + s2);
String literals are different to String objects. String s = "x" is not the same as String s = new String("x"). AFAIK the former creates a String literal in the String pool, unless the literal already exists, in which case it doesn't; the latter always creates a new String object.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
line7th from the bottom
Using break and continue (Objective 2.2)
"An unlabeled break statement will cause
As break will exit the loop.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Jon Frowd wrote:In the question posed on page 433, aren't 9 objects created? Isn't the space character on the last line also a String object?
System.out.println(s1 + " " + s2);
Until
System.out.println() there will be 8 objects created.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Rember, static inner classes can't access instance methods or variables.
I believe it should be "static nested class", right?
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Bert Bates wrote:
Also, THANKS to everyone for posting these! I tend to look into these in baches, so pretty soon I'll review all of these and give you all some feedback!
Bert
Hi,
I'm trying to find the official errata for SCJP Sun Certified Programmer for Java 6: Exam 310-065 book. The publisher's errata list doesn't list such. Is this thread what I'm looking for? Where can I find the feedback Bert mentioned in his post?
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
With either fragment, the first output must be yo.
I don't think this is so. It's possible for 'dude' to get printed first.
https://coderanch.com/t/657902/java-programmer-SCJP/certification/SCJP-Chapter-Threads-test
| My previous laptop never exploded like that. Read this tiny ad while I sweep up the shards. The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |










