Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ & Java - overloading operator

Tags:

java

c++

I have a difficult to understand the subject of overloading operator in C++ and Java.

For example, I define a new class Fraction:

class Fraction { 
public: 
    Fraction (int top, int bottom) { t = top; b = bottom; } 
    int numerator() { return t; } 
    int denominator() { return b; } 
private: 
    int t, b; 
};

and I want to overload the operator << for printing Fraction. How I do it? I need to overload it inside Class Fraction or outside Class Fraction?

In java - Is it possible to overload operator? How I can do it there (for example, I want to overload the operator +).

If there is a metrial about this subject, It will be great.

like image 432
Tom Avatar asked May 17 '26 10:05

Tom


1 Answers

In java - Is it possible to overload operator?

No, Java has no operator overloading.

like image 146
Bart Kiers Avatar answered May 19 '26 00:05

Bart Kiers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!