• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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 ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic