Results 1 to 6 of 6
- 06-19-2008, 07:30 PM #1
[SOLVED] Java operator overloading
I have an interesting question to ask. I have seen on a few forums that operator overloading is not possible in Java. So then, why can we use the following?
Integer a = new Integer(1); Integer b = new Integer(2); Integer c = a + b;
Just a strange thing I picked up. Thank you. ;)Eyes dwelling into the past are blind to what lies in the future. Step carefully.
- 06-19-2008, 07:42 PM #2
I believe but could be wrong, but operator overloading refers like in C++ where you change what an operator does. In C++ I could make the + really mean multiply or concatenate two strings. Java has no such function other that what is already defined in java.My IP address is 127.0.0.1
- 06-19-2008, 08:00 PM #3
Can you explain why my code snippet compiles and runs successfully?
Thank you. :DEyes dwelling into the past are blind to what lies in the future. Step carefully.
- 06-19-2008, 09:52 PM #4
Because I do believe correct me if I'm wrong but Integer can be made into int form in java. They are almost the same to a programmer in many aspects.My IP address is 127.0.0.1
- 06-26-2008, 05:39 AM #5
Based on the JavaDoc's first line:
The Integer class wraps a value of the primitive type int in an object. An object of type Integer contains a single field whose type is int.
Integer a = new Integer(1); Integer b = new Integer(2); Integer c = a + b; System.out.println(c);
- 06-26-2008, 07:35 PM #6
- By Albert in forum Advanced JavaReplies: 2Last Post: 11-26-2010, 02:12 AM
- By jimJohnson in forum New To JavaReplies: 2Last Post: 03-21-2008, 08:22 PM
- By padutch2 in forum New To JavaReplies: 2Last Post: 12-31-2007, 03:26 AM
- By Java Tip in forum Java TipReplies: 0Last Post: 12-01-2007, 08:33 PM
- By Syed.muddasir in forum New To JavaReplies: 6Last Post: 07-31-2007, 02:34 PM