Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

interview question

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why java does not support operator overloading?
 
Ranch Hand
Posts: 694
Mac OS X Eclipse IDE Firefox Browser
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java does have some pre-defined overloaded operators such as + which can mean either arithmetic operation or String concatenation depending upon the context, but you can't define your own overloaded operators as you can in C++.

The reason that the architects of Java decided to disallow operator overloading by Java developers is that it can be confusing when you see operators and not know whether they are the ones that are part of the language or whether they are the ones that a developer has overloaded.

In Java, there are not developer-defined overloaded operators, but it is possible for a Java developer to overload methods. Overloaded methods have the same name, but have different type and/or order of parameters.

It can still be confusing when you see a method. You have to ask yourself if there are two methods of the same name whether they are overloaded or overriden and whether they follow the rules to be legal.

Kaydell
[ August 28, 2007: Message edited by: Kaydell Leavitt ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic