158k views
3 votes
This semester we looked at three languages (C++, Java and Python). One common rule in all three class checklists (for C++, Java and Python) was a logical equivalence (equals) function. In C++ it was operator==; in Java it was equals; and in Python it was __eq__. Why does this rule exist in all three languages?

User Ajgreyling
by
7.9k points

1 Answer

2 votes

Answer:

The languages C++, Java, Python are Object Oriented Programming languages. What this means is that we create classes and then instantiate those classes. In C++ and Java, we use the new operator to instantiate the classes. So, if we want to display some data when we try to print the instance just like we print the variables of data types like int, double, string etc, we need to define what we need to display. It is because, class are just like data types like int, double etc. But as they are defined by the developer according to his/her needs, so the developer has to define what to print when they are printed.

User Jason Barile
by
6.8k points