Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

OCA/OCP Java SE 8 Programmer (Practice tests) Chapter 1 question 29 (Sybex)  RSS feed

 
Greenhorn
Posts: 3
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OCA/OCP Java SE 8 Programmer (Practice tests) Chapter 1 question 29 (Sybex)

++++++++++++++++++++++

QID: SE3CR45504
Q. 29  Given the following class definition, which command will cause the application to output the message White-tailed?



A. java forest.Deer deer 5 "White-tailed deer"Your selection is incorrect
B. java forest.Deer "White-tailed deer" deer 3
C. java forest.Deer Red deer White-tailed deer
D. java forest.Deer My "deer White-tailed"

SOLUTIONS
C.
The application prints the third argument of the input methods. Note that double quotes "" group input arguments.
Therefore, the third argument of Option A is White-tailed deer. The third argument of Option B is 3.
The third argument of Option C is White-tailed, making it the correct answer.
Finally, Option D only has two input arguments, leading to an ArrayIndexOutOfBoundsException trying to read the third argument at runtime.

++++++++++++++++++

However, my answer would be "Code does not compile, as 'theInput' is undefined".
Wrote and run this piece of code and indeed the result is compilation error:

>javac Deer.java
Deer.java:7: error: cannot find symbol
                System.out.print(theInput[2]);
                                 ^
  symbol:   variable theInput
  location: class Deer
1 error

Not able to find this topic in the blog, please point me to it if already reported.
thanks,
Elena
 
Ranch Foreman
Posts: 75
9
Eclipse IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Elena,

Welcome to the ranch!

The answer to your problem is that your Var-args parameter is named deerParams but you're referencing it as theInput. if you replace



with



your code should give the expected output!

-Zach
 
elena morton
Greenhorn
Posts: 3
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Zach,

This is not my code. It is "OCA/OCP Java SE 8 Programmer (Practice tests) Chapter 1 question 29 (Sybex)" test code.
Either code or answer needs to be corrected in there.

thanks,
Elena
 
Zach Rode
Ranch Foreman
Posts: 75
9
Eclipse IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've answered this question wrong. It seems I took a left turn and wandered out of the beginning java forum. Just shows I should take more time to read the post.

On topic though, you should probably report that question to the test makers. I'm sure they would be appreciative.

-Zach
 
author & internet detective
Marshal
Posts: 38250
623
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Elena: I agree that is an error. It's already listed in our errata

Zach: I'm one of the authors and I definitely appreciate hearing from readers about errata. The book says to post in this forum any errata or questions. So Elena did the right thing by posting here!
 
elena morton
Greenhorn
Posts: 3
Eclipse IDE Java Oracle
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, Jeanne for pointing me to the errata page, this helps a lot with the other tests I need to go through.

Kind regards,
Elena
 
Hey cool! They got a blimp! But I have a tiny ad:
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!