• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Doubt on Integer

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
As i know, The + operator is not defined for Integer objects, only for String objects.But the following program giving the out put " final value 7".Could anyone tell me why?

class IntegerTest
{
public static void main(String[] args)
{
Integer A, B, C ;
A = new Integer( 3 ) ;
B = new Integer( 4 ) ;
C = A + B ;
System.out.println( "Final value " + C ) ;
}
}


thanks in advance,
reena
 
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
15.18.2 Additive Operators (+ and -) for Numeric Types
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you are using Java 1.5; In Java 5, the code will very well run because of the AutoBoxing property.
But, if you try to run it using any other versions you may get an compilation error like:
----------------
IntegerTest.java:8: operator + cannot be applied to java.lang.Integer,java.lang.Integer
C = A + B ;
^
1 error
----------------
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic