aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes short data type question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "short data type question" Watch "short data type question" New topic
Author

short data type question

Yin Stadfield
Ranch Hand

Joined: Oct 13, 2012
Posts: 34

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
internet detective
Marshal

Joined: May 26, 2003
Posts: 29287
    
140

Yin,
Starting Java 5, short and Short can both be used due to auto-boxing. The compiler automatically adds the conversion code for you.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Yin Stadfield
Ranch Hand

Joined: Oct 13, 2012
Posts: 34

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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: short data type question
 
Similar Threads
why cannot a normal method be invoked from a static context
why can't a function be called from a static context
Chapter 1. Question 9
Help on this SCJP question
Java beginner---please help