This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Chapter 1 Self Test Question 3 from Sierra K., Bates B. - OCA OCP Java SE 7 Programmer I & II

 
Kaleem Anwar
Ranch Hand
Posts: 40
2
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Here is question from the self test of book "Sierra K., Bates B. - OCA OCP Java SE 7 Programmer I & II Study Guide - 2015", asking for the output. Can anyone explain and provide answer?




Regards,
Kaleem
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kaleem,
The idea is for you to type in the code and run it to see what the output is. That's why it is a self test. The learning comes from actually trying it. If we just tell you the output, we are stealing that learning from you.

Once you've run it, post the answer here and any doubts you have as to why that is the answer.
 
Kaleem Anwar
Ranch Hand
Posts: 40
2
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:Kaleem,
The idea is for you to type in the code and run it to see what the output is. That's why it is a self test. The learning comes from actually trying it. If we just tell you the output, we are stealing that learning from you.

Once you've run it, post the answer here and any doubts you have as to why that is the answer.



Actually, i tested it and the output was "-A." , which seems correct looking at the code. The book answer says the correct output should be "A." , that's why I posted for better understanding. Hope you guys put some light on this.

Thanks.

 
Henry Wong
author
Marshal
Pie
Posts: 22113
88
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kaleem Anwar wrote:
Actually, i tested it and the output was "-A." , which seems correct looking at the code. The book answer says the correct output should be "A." , that's why I posted for better understanding. Hope you guys put some light on this.


It should be "-A.". Perhaps you could look to see if there is a mention in the errata for the book?

Henry
 
Kaleem Anwar
Ranch Hand
Posts: 40
2
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
Kaleem Anwar wrote:
Actually, i tested it and the output was "-A." , which seems correct looking at the code. The book answer says the correct output should be "A." , that's why I posted for better understanding. Hope you guys put some light on this.


It should be "-A.". Perhaps you could look to see if there is a mention in the errata for the book?

Henry


Thanks Henry
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kaleem Anwar,

First of all, a warm welcome to CodeRanch!

Kaleem Anwar wrote:Can anyone explain and provide answer?

Kaleem Anwar wrote:Actually, i tested it and the output was "-A." , which seems correct looking at the code. The book answer says the correct output should be "A." , that's why I posted for better understanding. Hope you guys put some light on this.

You are absolutely correct: the code snippet you posted prints "-A." but this code is NOT equivalent to the code of self question 3 (on page 75). And that's why you get another output as the book mentions, but the answer in the book is definitely spot-on!

The study guide uses the following command line: java _ - A .

You turn this into the following array:But that's wrong! The correct array (which is equivalent to the program arguments of the aforementioned command line invocation) isYou have included the class name ("_") into your array, but the class name is not a part of the program arguments. To launch a program, you invoke java class [ arguments ] (arguments is optional). That's why the class name is not part of the arguments array.

Hope it helps!
Kind regards,
Roel
 
Kaleem Anwar
Ranch Hand
Posts: 40
2
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much Roel for providing explanation.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic