I have a Java assignment. I am supposed to make a class with two "Multiply" methods one returns the result and the other returns void and modifies the object that invokes it.
How is this possible in Java? Just giving me some keywords for where to look would be very helpful. Inheritance? Polymorphism? Interfaces? Abstract classes?
Thank you very much for the answer. The problem is both methods should be taking the same argument. That's why overloading doesn't work. Actually the return type is not a part of the method signature in java. It is only the specifiers and name and the arguments. This is the desired output.
1 Imaginary im1 = new Imaginary(3 ,4) ;
2 Imaginary im2 = new Imaginary( -2 , 10) ;
4 im1.add ( im2 ) ; // result im1 = 1 + 14 i
5 Imaginary im3 = im2. add( im1) ; // result im3 = 1 + 14 i
See both functions are invoked with the same name and takes the same arguments. Overloading unfortunately is not the answer here. I am guess Professor expects us to use polymorphism or interfaces or generic or idk.
I mean I will have to study all those anyway but the homework due is before the final :P better get this done first but still don't know where to begin. I guess I will have to finish all hundreds of pages of slides then hopefully have an idea about the solution lol