0

Possible Duplicate:
Operator overloading in Java

I have a small question. If operator << used for cout purpose in C++ is overloaded, can we do the same in Java? And if we can, what will it correspond to?

Thank you.

Community
  • 1
  • 1
ashish nirkhe
  • 689
  • 3
  • 10
  • 22

3 Answers3

5

Java doesn't have operator overloading.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
2

The closest thing to cout << overloading in Java is the ToString method that every class can replace.

IronMensan
  • 6,761
  • 1
  • 26
  • 35
  • 1
    not exactly. `<<` is a stream operator when used in the context of `cout`. – Daniel A. White Sep 11 '11 at 21:10
  • Even if it's not an exact equivalent, it is still a fair bid for the _closest thing_ to customizing how a particular type is printed to a stream. – hmakholm left over Monica Sep 11 '11 at 21:14
  • @daniel It is not exactly the same, but it is the closet thing I can think of and that is what the OP is asking for, what in Java is most like cout << in Java. (I can't type backquote on my phone) – IronMensan Sep 11 '11 at 21:20
  • I see what Daniel is saying in that they're completely different. But I also see Iron's perspective in that they're both the "go to approach to display". – corsiKa Sep 11 '11 at 21:28
1

There is no operator overloading in Java.

K-ballo
  • 80,396
  • 20
  • 159
  • 169