• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Errata on Page xli, Introduction, #12 (Java OCA 8 Programmer I Study Guide, Sybex)

 
Yasar Kunduz
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

Page xli, Introduction, #12

Answer B (Color:null), I think this is not a correct answer, because on lines 3-5 constructor calls the other constructor with a parameter this("white").
So, the correct answer should be "Color:white", am I wrong?

Kind regards,
Y. Kunduz
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Yasar Kunduz,

First of all, a warm welcome to CodeRanch!

Yasar Kunduz wrote:Answer B (Color:null), I think this is not a correct answer, because on lines 3-5 constructor calls the other constructor with a parameter this("white").
So, the correct answer should be "Color:white", am I wrong?

Yes, you are wrong! The study guide is spot-on and answer B is the correct answer.

Let's first share the appropriate part of the code snippet, so other ranchers can join this discussionYou are indeed correct that the constructor on lines 3-5 invokes the other constructor with parameter "white". But if you look closely to this constructor, you'll notice that the parameter color is assigned to itself and not to the instance variable color. Because both the parameter and the instance variable have the same name, you need to distinguish between both variables. If you simply use color, you refer to the parameter (and not to the instance variable). To refer to the instance variable you have to use this.color. So if the second constructor wasoryou would have been correct and the correct answer would have been C.

Hope it helps!
Kind regards,
Roel
 
Yasar Kunduz
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Roel,

"look closely to the constructor" this is the key ;)
 
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
Yasar Kunduz wrote:"look closely to the constructor" this is the key ;)

Exactly! And this question literally shows how focused you must be when taking the actual exam. Every question requires complete concentration. Even if you are distracted for just a second, you might miss a compiler error and answer that question incorrectly.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic