Two Laptop Bag
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Wrapper Classes Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Wrapper Classes" Watch "Wrapper Classes" New topic
Author

Wrapper Classes

Saumya Tangeda
Greenhorn

Joined: Jul 09, 2006
Posts: 24
Why does the expression: new Short(1); causes a compile-time error
while the expression: new Short("1"); does not?
Saumya Tangeda
Greenhorn

Joined: Jul 09, 2006
Posts: 24
Sorry, the first expression is resulting in run-time error NOT compile-time error.I understand why, but i don't get why the second one is OK.
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2341
No, the first one results in a compile-time error. There is no constructor
in Short.java that accepts an int.
Buhi Mume
Greenhorn

Joined: Jul 16, 2006
Posts: 17
By default, the number in
new Short(1)
is of type int. Thus, it produces compile error.

 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Wrapper Classes
 
Similar Threads
Leading + in constructor
S&B 1.5 Chapter 6, Question 4 explanation D
an int outside a for loop, which is printed after the for loop
How does this code works ?
Type Conversion doubt