• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Compiling errata for K&B, SCJP 6

 
Bob Condon
Greenhorn
Posts: 2
Android IntelliJ IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ch. 3 Qn. 12
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.
 
Vijay Tyagi
Ranch Hand
Posts: 52
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a line in Chapter 1 of KB SCJP 6 book

"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.
 
Yalvin Duha
Ranch Hand
Posts: 41
Eclipse IDE Java Slackware
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know if this is a valid errata, but Chapter 7, Self-Test section, Question 3 (answered on page 648-649) says that the correct choice is "E" (a run-time error).

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.
 
Carrie Hall
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I may be missing something here, but I tried to compile Chapter 7 Self Test - q1 and could not compile any of the listed answers.

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>

 
sarvesh dikonda
Ranch Hand
Posts: 58
Firefox Browser Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Chris Devine
Greenhorn
Posts: 3
Clojure Linux Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the Chapter 1 Self-test, question 6:

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.

 
Alan Cowap
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Chris Devine
Greenhorn
Posts: 3
Clojure Linux Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Francky Boy
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Alan Cowap
Greenhorn
Posts: 6
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Francky Boy
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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


 
Shannon Sims
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Error??? Page 76, question #7, the answer on page 83 states that C, D and F are correct. However, since line 9 is not initialized, this should be a compile error according to page 71 - "Local Variables - Local variables don't get default values, so they must be initialized before use". Therefore, the answer should be C, D, E and F, please verify?

Thank you.

Never mind, the key word to watch for was "before use".
 
Joe Boman
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
doubt in k&b, page 92,
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
 
Omar Nassar
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to thank you all for these feedback
 
Jon Frowd
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
 
Steven Squeers
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Daya Moon
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chapter 5. page 398.
line7th from the bottom
Using break and continue (Objective 2.2)
"An unlabeled break statement will cause the current iteration of the innermost looping construct to stop and, the line of code following the loop to run."
As break will exit the loop.
 
Daya Moon
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.

 
Math Silva
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Page 682. Last sentence says:

Rember, static inner classes can't access instance methods or variables.


I believe it should be "static nested class", right?
 
YinLi Tao
Greenhorn
Posts: 7
Debian Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Richard Hayward
Ranch Hand
Posts: 114
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chapter 9: Threads self test q15

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.

http://www.coderanch.com/t/657902/java-programmer-SCJP/certification/SCJP-Chapter-Threads-test
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic