• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

wrapper classes

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What will happen if you attempt to compile and run the following code?



1) 19 followed by 20
2) 19 followed by 11
3) Compile time error
4) 10 followed by 1

When I compiled i got the output as option 2(19 followed by 11).

But actual answer given is as below:
Compile time error

The wrapper classes cannot be used like primitives.

Depending on your compiler you will get an error that says someting like "Error: Can't convert java lang Integer". Wrapper classes have similar names to primitives but all start with upper case letters.

Thus in this case we have int as a primitive and Integer as a wrapper. The objectives do not specifically mention the wrapper classes but don't be surprised if they come up.

It would be nice if someone explain me about this.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I get the same result (that is, 19 followed by 11). What is the source of this question? Is it possible that it came from a Java 1.4 mock exam? In other words, was it written prior to the introduction of autoboxing?
 
ashni Prakash
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi rick,

I checked now,the question is from JDK1.4 mock exam.Its prior to autoboxing,I have jdk1.5 version.So is it because of difference in versions.
 
It sure was nice of your sister to lend us her car. Let's show our appreciation by sharing this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic