aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Study Guide 6 -- Chapter2 Self Test Question 15 on page 181. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Study Guide 6 -- Chapter2 Self Test Question 15 on page 181. " Watch "Study Guide 6 -- Chapter2 Self Test Question 15 on page 181. " New topic
Author

Study Guide 6 -- Chapter2 Self Test Question 15 on page 181.

Graciela Zaffarana
Greenhorn

Joined: Jan 09, 2010
Posts: 17
Study Guide 6 -- Chapter2 Self Test Question 15 on page 181.

Hello Fellas ...

(1) It is clear that the code on question 15 compiles; I verified that. But, does int 7 in line 12 --- "sifter(7)" get boxed by the compiler behind the scenes? Really? Do I have to read more through the book to get an answer on how the compiler does it, or can you tell me? Without having to declare it as: new Integer(7)? Please, comment. ( It goes without saying that I had chosen Compilation fails because I thought that 7 was not an Object but primitive data. )


(2) Also, It occurred to me to comment out the version of method sifter that expects an Object to see if array "aa" got routed to version of sifter with argument equal to A[]... a2, and indeed it did! So, is there more than one answer to this question? or should we consider the comment " In general, overloaded var-args methods are chosen last." as the law of the land? ---

NOTE: In the process of recompiling the code after commenting out line 18 sifter(Object o) , I had to also comment out line 12 sifter(7) --- Interestingly enough, the compiler error sort of directed me to think that it views 7 (like I do) as a primitive integer and not as an object of type Integer. Compiler error message is somewhat misleading in my view.

Greatly appreciate your input.

Best,

Wanna be a "Java compiler thinking machine"
Neha Daga
Ranch Hand

Joined: Oct 30, 2009
Posts: 504
you should post code as everyone may not be having book with them.


SCJP 1.6 96%
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

1) I made that mistake in chapter 1 selftest question number 9 . But you'll read all about boxing and related stuff in the next chapter.
2) In chapters to come (don't know which one) the order in which methods are called will be explained.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Graciela Zaffarana
Greenhorn

Joined: Jan 09, 2010
Posts: 17
Hey! but at least in question 9 of Chapter 1 "myGold" is boxed; in question 15 of Chapter 2 it is not. Okay, okay ... I will hang in there one chapter longer to be enlightened.

Here is the code: ( I hope that I am posting it right -- with line numbers --- when I click the <submit > ; otherwise, tell me how, I will know better next time around. Cheers!

Graciela Zaffarana
Greenhorn

Joined: Jan 09, 2010
Posts: 17
Sorry, I posted the code with my changes. Here is the original as showing on the Self Test question:

Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9305
    
  17

Okay I'm confused. Can you post the code of the book and the doubts that you have together. I can't understand which is the actual code and the questions in your mind as its distributed here and there...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Neha Daga
Ranch Hand

Joined: Oct 30, 2009
Posts: 504
yes on line 12 in sifter(7); 7 is automatically boxed by compiler and the second observation is correct that when you comment out the sifter(object o) method it will go to var args version but there is only one answer to the question as object version is not commented and var args is always chosen the last so object version will be chosen.
or should we consider the comment " In general, overloaded var-args methods are chosen last." as the law of the land? ---


yes you should always stick to it.
Graciela Zaffarana
Greenhorn

Joined: Jan 09, 2010
Posts: 17
Okay. Thank you. Til next round ...

G.Z.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Study Guide 6 -- Chapter2 Self Test Question 15 on page 181.