D-Day
Java Programming

What is overloaded operator?

567

Top Answer
User Avatar
Wiki User
Answered
2011-01-23 08:40:56
2011-01-23 08:40:56

Java does not support operator overloading. Operator overloading is the scenario where you overload a particular operator to do something that it is not designed to do.

Ex: if you make the operator "*" do addition or the operator "-" do multiplication, imagine the chaos that would ensue in your program. So the java designers blocked this feature of operator overloading.

001
๐ŸŽƒ
0
๐Ÿคจ
0
๐Ÿ˜ฎ
0
๐Ÿ˜‚
0
User Avatar

Related Questions


The prefix increment operator is overloaded as operator++() while the postfix increment operator is overloaded as operator++(int).


There are 5 operators which cannot be overloaded. They are: * .* - class member access operator * :: - scope resolution operator * . - dot operator * ?:: - conditional operator * Sizeof() - operator Note:- This is possible only in C++.



* Assignment operator : = * Function call operator : () * Subscripting operator : [] * Class member access operator.



conditional operator , size of operator , membership operator and scope resulation operator can not be overload in c++


No, java does not support explicit operator overloading. You can use an operator only for its intended purpose. But the "+" operator is implicitly overloaded. It can be used to add two numbers as well as concatenate two strings. Apart from this operator all other operators can be used only for their specific purpose.


The following C++ operators cannot be overloaded.... Member selection.* Pointer to member selection:: Scope resolution:> Base operator?: Conditional# Preprocessor symbol## Preprocessor symbol



Java does not support user defined operator overloading.The operator '+' is overloaded in Java and can be used for adding both numbers and Strings.


The assignment operator. If you do not declare one in your class, the compiler generates one for you.


class travel {...travel &operator=( some type );... or ...travel operator=( some type );...};


1. Member-of operator (.) 2. Pointer-to-member-of operator (.*) 3. Ternary condition operator (?:) 4. Scope resolution operator (::) 5. sizeof operator 6. typeid operator




The operators that cannot be overloaded in C++ are:. member selection.* pointer to member selection:: scope resolution:> base?: conditional# preprocessor## preprocessor


The only "special" operators in C++ are those that cannot be overloaded. That is; the dot member operator (.), pointer to member operator (.*), ternary conditional operator (:?), scope resolution operator (::), sizeof() and typeof().


Java does not support operator overloading. Operator overloading is the scenario where you overload a particular operator to do something that it is not designed to do. Ex: if you make the operator "*" do addition or the operator "-" do multiplication, imagine the chaos that would ensue in your program. So the java designers blocked this feature of operator overloading.


You cannot explicitly overload an operator in Java but by default the + symbol is overloaded. You can use it to add numeric values as well as concatenate strings.


obj1 = obj2; Operator "=" can be overloaded either by the member function or by the friend operator function. In case of the friend function, the obj1 and obj2 are should be from the different classes. If they are from the same class, the compilation error will occur. We can't use the "this" pointer in the friend function since it is not the member function of the class. So, If both objects are from the same class it is better to for operator function (operator=) as member function. If the objects are from the different class, then the operator function as friend function is advisable.


The ternary operator (known as the conditional operator in C++) cannot be overloaded because it is impossible to pass a test operand and two expression operands (either or both of which may be comma-separated) to a function. You can only pass values or references as arguments to a function. Even if it were possible, built-in functions and operators that rely on the conditional operator would likely break. Like all the other operators that cannot be overloaded (sizeof, typeid, ::, . and .*) the results must always be predictable because built-in operators and functions rely on them so heavily.


No. The ternary operator (known as the conditional operator in C++) cannot be overloaded because it is impossible to pass a test operand and two expression operands (either or both of which may be comma-separated) to a function. You can only pass values or references as arguments to a function. Even if it were possible, built-in functions and operators that rely on the conditional operator would likely break. Like all the other operators that cannot be overloaded (sizeof, typeid, ::, . and .*) the results must always be predictable because built-in operators and functions rely on them so heavily.


You cannot overload the sizeof() operator because that could introduce uncertainty in its evaluation. The sizeof() operator must always produce an accurate and logically predictable result, thus all user-intervention is completely forbidden.


Assignment(=) operator is a special operator that will be provided by the constructor to the class when programmer has not provided(overloaded) as member of the class.(like copy constructor). When programmer is overloading = operator using friend function, two = operations will exists: 1) compiler is providing = operator 2) programmer is providing(overloading) = operator by friend function. Then simply ambiguity will be created and compiler will gives error. Its compilation error.


There are 7 C++ operators that connot be overloaded. They are... . select .* pointer select :: scope :> base ?: conditional # preprocessor ## preprocessor



Copyright ยฉ 2020 Multiply Media, LLC. All Rights Reserved. The material on this site can not be reproduced, distributed, transmitted, cached or otherwise used, except with prior written permission of Multiply.