This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin for Android App Development and have Peter Sommerhoff on-line!
See this thread for details.
Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

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
 
Rancher
Posts: 89
13
Chrome Eclipse IDE Java MySQL Database Scala Tomcat Server Windows
  • 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
Rancher
Posts: 89
13
Chrome Eclipse IDE Java MySQL Database Scala Tomcat Server Windows
  • 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
Posts: 39129
723
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
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!