• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

short data type question

 
Yin Stadfield
Ranch Hand
Posts: 58
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the 9th question in Chapter 1 SCJP 6 Study Guide by Kathy Sierra and Bert Bates:

9. Given:
What is the result?
A. 13
B. Compilation fails due to multiple errors
C. Compilation fails due to an error on line 6
D. Compilation fails due to an error on line 7
E. Compilation fails due to an error on line 11
Answer:
® ✓ D is correct. The Short myGold is autoboxed correctly, but the countGold() method
cannot be invoked from a static context.
®˚ A, B, C, and E are incorrect based on the above information. (Objective 1.4)

So I thought C must be correct because data type short must be "short" not "Short", am I missing something? All primitive types starts with a lowercase letter, right?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34860
369
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yin,
Starting Java 5, short and Short can both be used due to auto-boxing. The compiler automatically adds the conversion code for you.
 
Yin Stadfield
Ranch Hand
Posts: 58
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:Yin,
Starting Java 5, short and Short can both be used due to auto-boxing. The compiler automatically adds the conversion code for you.


I never knew that. Thanks for the info, Jeanne!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic