Forums Register Login

short data type question

+Pie Number of slices to send: Send
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?
1
+Pie Number of slices to send: Send
Yin,
Starting Java 5, short and Short can both be used due to auto-boxing. The compiler automatically adds the conversion code for you.
+Pie Number of slices to send: Send
 

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!
them good ole boys were drinking whiskey and rye singin' this'll be the day that I die. Drink tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 994 times.
Similar Threads
Chapter 1. Question 9
Java beginner---please help
why can't a function be called from a static context
Help on this SCJP question
why cannot a normal method be invoked from a static context
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 10:43:31.