• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Chapter 1 Review Question #14 (Java OCA 8 Programmer I Study Guide, Sybex)

 
christophe Leconte
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am currently reading the OCA Java SE 8 Programmer I Study guide of Boyarsky and Selikoff and I have a question about the solution of review question #14 of chapter 1.


I don't understand why the only valid response is D.

For example if I replace "INSERT CODE HERE" by package my.directory.name.A;
and I launch the command : javac ./named./A/Bird.java. I have no compilation error.

Could you help me to understand my error ?

 
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
Hi christophe Leconte,

First of all, a warm welcome to CodeRanch!

christophe Leconte wrote:I don't understand why the only valid response is D.

For example if I replace "INSERT CODE HERE" by package my.directory.name.A;
and I launch the command : javac ./named./A/Bird.java. I have no compilation error.

Strictly speaking you are correct: you can insert any of those package statements and the code will compile successfully. But the question is clearly testing your knowledge about package statements. So from the naming of the current directory (/my/directory), you should know that my.directory can't be a part of the package statement (and therefore B can't be a correct answer).
In such a question it's very important to be aware of the "context of a question". This question only has answer options with package statements and in the question itself the directories where the Java source code file resides and from where the source code file will be compiled is the same, so it's clearly about choosing the most appropriate answer. In this thread you'll find a nice discussion about this "context of a question", it's definitely worth reading.
In this topic you'll find a discussion about exactly the same review question.

Hope it helps!
Kind regards,
Roel
 
christophe Leconte
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your response, I will try to keep in mind the context of the question.

Best regards.

Christophe.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic