• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Chapter 1, page 33 - Class Cloo will not be visible to the third class Toon.

 
Ron Teeple
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Class Cloo will not be visible to the third class Toon.
You can make it visible by making class Cloo public or moving class Toon to package nocert.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's clearly about K&B7.

Could you give some context about this post? Do you have a question about this code? Do you think it's a mistake in the book?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35269
383
Eclipse IDE Java VI Editor
 
Ron Teeple
Greenhorn
Posts: 2
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Roel for your response. The text displays three classes, Roo, Cloo that extends Roo, and Toon that instantiates Cloo.
It goes on to say "some other class can call doRooThings()on a Cloo instance, ..." and then it lists the Toon class. The natural assumption is that this is a working code example. But, the Toon class has no visibility to Cloo. I would suggest that either the code be modified so that it compiles (making class Cloo public or moving class Toon to package nocert), or asking the reader to determine what to change so that the code compiles and executes OK. This same code example is contained in previous versions of the Java certification book going back to the Java 2 certification book and previous threads have mentioned it.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ron Teeple wrote:The text displays three classes, Roo, Cloo that extends Roo, and Toon that instantiates Cloo.
It goes on to say "some other class can call doRooThings()on a Cloo instance, ..." and then it lists the Toon class. The natural assumption is that this is a working code example. But, the Toon class has no visibility to Cloo. I would suggest that either the code be modified so that it compiles (making class Cloo public or moving class Toon to package nocert)

If I look at the code of classes Roo, Cloo and Toon; I'm a little bit in doubt and I'll explain why.

If you look at the code of classes Roo and Cloo, you'll see package statements and appropriate import statements (if needed). But if you look at the code of class Toon, you don't see any package nor import statements. That could imply class Toon is defined in the same source code file as class Cloo (and then the code compiles successfully). And I think that's what's happening here...

Someone could argue class Toon is defined in the default package (because there is no package statement). But if class Toon was really intended to be in the default package, then there must be an import statement for class Cloo or the fully qalified name notcert.Cloo must be used in the code snippet (both will still fail to compile because class Cloo has default access). But none of these are used in the code snippet of class Toon, so that's why I think class Toon is not intended to be defined in the default package (and invigorates my previous statement)

But on the other hand I think this is an ambiguity which could confuse readers. And that isn't the intent of a study guide. So I'll be adding this to the errata overview as well. I propose the most easy fix: simply adding a package statement to class Toon. (marking class Cloo as public also requires an import statement in class Toon). So the new code will look like this:


Hope it helps!
Kind regards,
Roel

PS. If you should discover any other errata items in K&B7, you can post them in this dedicated thread.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Added to the errata overview.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic