- World's Largest Collection of Interview Questions
Start Your Own website Now
Sponsored Links

Interview Questions
Our Services

Get 9,000 Interview Questions & Answers in an eBook.

  • 9500+ Pages
  • 9000 Question & Answers
  • All Tech. Categories
  • 14 MB Content

    Get it now !!

    Send your Resume to 6000 Companies

    Question :
    Why operator overloading is not there in java?
    Category Core Java Interview Questions
    Rating (0.4) By 1897 users
    Added on 8/24/2009
    Views 1923
    Rate it!

    C++ has proven by example that operator overloading makes code almost impossible to maintain. In fact there very nearly wasn?t even method overloading in Java, but it was thought that this was too useful for some very basic methods like print(). Note that some of the classes like DataOutputStream have unoverloaded methods like writeInt() and writeByte().

    I belive Operator Overloading exists in Java.

    For ex:
    Operator + :

    '+' has been over ridden to add when its used with number. The '+' operator is also used as Concatenating operator in case of Strings.

    Plz let me know in case of any clarification required.

    Posted by: Divya    

    Contact Divya Contact Divya

    Operator overloading makes the code more complex and less readable. Also we could define different methods in the same class like plus(),plusplus(), minus() etc and thus bringing operator overloading in Java

    Posted by: Ponnu    

    Contact Ponnu Contact Ponnu

    I guess,Operator overloading is not supported in Java as its create lot of confusion instead of solving the problems.

    Posted by: Venu    

    Contact Venu Contact Venu

    Operator Overloading
    An operator is overloaded if it is bound to multiple definitions. When the operator is used in an expression,
    which definition to use is determined based on the number and type of the operands. Examples:
    ? in Java, + is used both for addition and string concatenation
    ? in almost all programming languages, the arithmetic operators (+, -, *, ...) are overloaded to work
    on both integer and floating point types. Note that integer addition and floating point addition are
    different operations in assembly language.
    Notes on overloading:
    ? many languages (C++, Ada, C#) allow the programmer to overload operators
    ? Java does not
    ? overloading can help program readability if the overloaded meaning of the operator is similar to the
    standard meaning
    ? overloading can hurt program readability if the overloaded meanings of the operator are very different
    from each other and/or the standard meaning
    ? overloading can reduce reliability by weakening the compiler's ability to detect type errors
    ? by definition, overloading must always be resolved statically. The compiler must be able to determine
    which meaning is meant by the (static) types of the operands.

    Posted by: Geetha Adhikeshavalu    

    Contact Geetha Adhikeshavalu Contact Geetha Adhikeshavalu

    java does not support method overloading
    But you can see a "+" operator is overloaded in java. it is used for string concatenation as well as addition. but it is a built inside java. a user or a programmer was not able to overload that operator anymore. In that sense java does not support operator overloading.

    But a programmer can overload method overloading is supported in java.

    There were two major reasons why operator overloading wasn't allowed in Java: "cleanliness" and compiler complexity..
    Given the human tendency to assign specific meanings to single symbols, it is hard to get programmers to wrap their heads around multiple meanings for operators.

    Posted by: Athira.V    

    Contact Athira.V Contact Athira.V

    If you have the better answer, then send it to us. We will display your answer after the approval.
    Rules to Post Answers in

  • There should not be any Spelling Mistakes.
  • There should not be any Gramatical Errors.
  • Answers must not contain any bad words.
  • Answers should not be the repeat of same answer, already approved.
  • Answer should be complete in itself.
  • Name :*
    Email Id :*
    Answer :*
    Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
    Process Verification  Enter the above shown code:*
    Inform me about updated answers to this question

    Related Questions
    View Answer
    What modifiers are allowed for methods in an Interface?
    View Answer
    What is a local, member and a class variable?
    View Answer

    Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here - Best Freshers & Experienced Jobs Website.

    View ALL Core Java Interview Questions

    User Options
    Sponsored Links

    Copyright ©2003-2015, All Rights Reserved.
    Privacy Policy | Terms and Conditions

    Download Yahoo Messenger | Placement Papers| FREE SMS | ASP .Net Tutorial | Web Hosting | Dedicated Servers | C Interview Questions & Answers

    Testing Articles | Testing Books | Testing Certifications | Testing FAQs | Testing Downloads | Testing Interview Questions | Testing Jobs | Testing Training Institutes

    Cache = 0.015625 Seconds