• 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

adding an argrument

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can someone give me some ideas on how to do something....i need to create my own add method.... num1.add(num2); i want to write my own add method....how do i get this: num1 + num2....
my add method will be more complicated than this....i just want to be pushed in right direction....
------------------
 
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java does not support operator overloading. A Java programmer can sleep well at night knowing that '+' will always be used to add two numeric primitives, concatenate Strings, or specify the sign of a numeric primitive.
Also, please change your name to one that meets that JavaRanch naming policy.
[This message has been edited by David Garland (edited August 25, 2001).]
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to override the default "add" method of the object class...I want to take two objects and add the arrays that are stored in them together...

foo1.add(foo2);

//that add method will call whatever the foo1 is and use its add method to add the arrays...If u have any idea, tell me or just push me in the right direction...if u understand.....dont you use the "this" keyword to help compare them or something...
[This message has been edited by Josey Muney (edited August 26, 2001).]
 
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is used to "point" to the current instance, or object, of a class. For instance:

this refers to the instance just created (since myClass() is a constructor), and says "make this instances someInt equal to the someInt argument that was passed as a parameter".
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Josey,
I guess this is what you wanted

Tell me, whether it works fine or not.Remember this could be changed according to your needs
THANKS
(edited by Cindy to format code and put blanks around < sign so it doesn't function like html)

[This message has been edited by Cindy Glass (edited August 27, 2001).]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic