• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Test Question classes and packages (Java OCA 8 Programmer I Study Guide, Sybex)

 
RichardH Marais
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am reading a study guide for the OCA 8 exam. The book says the following code will compile. I think it won't due to a name conflict on 'Water', but don't currently have a pc to test it. Also it is 3 separate classes, so I can't test it online. Please can someone test it for me?

Much appreciated.





 
Felipe Kunzler
Ranch Hand
Posts: 35
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

It will compile since both classes Water are in different packages.
When you make a reference of Water in WaterFilter, you are importing all classes of the package "aquarium", but not "aquarium.jellies". So only the first Water will be used in WaterFilter.
That's why it compiles
 
RichardH Marais
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you
 
Campbell Ritchie
Sheriff
Posts: 51348
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please always use the code button; I shall go back and edit the code for you, and you'll see how much better it looks Also make sure to indent the code correctly … or when copying from a certification book, indent the code exactly as in the book. They like to print misleading or incorrect indentation in some of those books, to try and catch you out.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic