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.

0

3 Answers 3

5

Java doesn't have operator overloading.

Sign up to request clarification or add additional context in comments.

Comments

2

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

4 Comments

not exactly. << is a stream operator when used in the context of cout.
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.
@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)
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".
1

There is no operator overloading in Java.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.