• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Chapter 2 Review Question 5 (Java OCA 8 Programmer I Study Guide, Sybex)

 
Ranch Hand
Posts: 75
Eclipse IDE AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Should not the line no 6 be like :

The datatype of variable on the left hand side should be same as the type of array/Iterable. Integer and int are not o the same typr then why will the code compile?
Am I missing something that I will learn in next chapters?

Moreover wanted to clarify that in unary operator i++, the value first gets incremented and then it returns the origunal(old) value. Is my understanding correct?
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Saumyaraj Zala wrote:The datatype of variable on the left hand side should be same as the type of array/Iterable. Integer and int are not o the same typr then why will the code compile?


Since Java 5 you have the autoboxing feature. In short: if you have a primitive value, Java will convert it automatically to the relevant wrapper class for you (when needed). And it works the other way around as well: if you have a wrapper class object, Java converts it automatically to the relevant primitive type for you (when needed). That's called unboxing and that's what happens here in this code snippet.

Saumyaraj Zala wrote:Am I missing something that I will learn in next chapters?


It is explained in the study guide at page 136. And also in this forum you find useful and valuable explanations on autoboxing: e.g. here, here and here. If you have carefully read (and understood) all these topics, you will definitely ace every question on autoboxing on the actual exam

Saumyaraj Zala wrote:Moreover wanted to clarify that in unary operator i++, the value first gets incremented and then it returns the origunal(old) value. Is my understanding correct?


Everything you need to know about the post-increment operator can be found in this topic. It has excellent explanations and many illustrative code snippets. Definitely worth reading!

Hope it helps!
Kind regards,
Roel
 
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic