File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Qn on Wrapper classes. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Qn on Wrapper classes." Watch "Qn on Wrapper classes." New topic

Qn on Wrapper classes.

Girish Nagaraj
Ranch Hand

Joined: Apr 19, 2006
Posts: 153
Look at the following snippet of code from Marcus green mock exam

Integer ten = new Integer(10);
Long nine = new Long (9);
System.out.println(ten + nine);

int i=1;
System.out.println(i + ten);

Output is 19 followed by 11.
But what anwer says is :

Compile time error

The wrapper classes cannot be used like primitives.

Why the diff. I am using java sdk 1.5.
Will the output be diff. if I use sdk 1.4.
Shaliey Gowtham
Ranch Hand

Joined: Mar 20, 2006
Posts: 104
Only from 1.5 you having unboxing
This code is valid only from 1.5 so in 1.4 its a compiler error
Deepak Bala

Joined: Feb 24, 2006
Posts: 6662

You can use the -source 1.4 option to see what would happen with java 1.4

SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
I agree. Here's the link:
subject: Qn on Wrapper classes.
It's not a secret anymore!