Hama Kamal wrote:
hey guys,,, please check the problem bleow
1-is it a correct way to call the method in this way?
yes if that method has a return type.
Hama Kamal wrote:
2-when i run it it gives this error
this is not an error. it is just default string representation of your Rectangle object. if you want the representation more meaningful, then override toString method in Rectangle class.
thanks alot for your reply ,,, but according to bleow method it shuold return either rectOne or rectTwo! but it does not
i mean the output is like this now:
Width of rectOne: 100
Heigh of rectOne: 200
Area of rectOne: 20000
X Position of rectTwo: 23
Y position of rectTwo: 94
X positon of rectTwo: 40
Y positon of rectTwo:72
createobjectdemo.Rectangle@c17164 but it should be either rectOne or rectTwo am i right?
BUILD SUCCESSFUL (total time: 1 second)
the problem is that you are returning something of type 'Object'. And you print the 'Object' which invokes the default 'toString' method. Hence you get the default string Seetharaman mentions. If you want to print the contents of rectOne or rectTwo you need to cast the return.
Hello Hama Kamal, hello Ranchers...@Hama could you be kind enough to show us how you overrode the toString() method? I am unable -at the moment- to put together an 'effective' override of the toString() method in such a way that it will return 'rectOne' OR 'rectTwo' according to the return of the findLargest() method in line 43 of the main class:
I know how to override the toString() method, but how can I 'condition' the output of the toString() method in such a way that it will display 'rectOne' OR 'rectTwo'
I will appreciate your help and that of any other coleague.
In Your Pursuit Towards Certification, NEVER Give Up.
Ikpefua, Rectangle has only height, width and point. You have to use ONLY those in your toString() method.
Why would you want to employ more than 1 Rectangle instances?
- the cast Rectangle otherRect = (Rectangle)other; is not needed.
- public Object findLargest(Object object1, Object object2) could very well be static
- public Object findLargest(Object object1, Object object2) could very well have a signature of findLargest(Rectangle object1, Rectangle object2) , no point in having arguments of type Object.
Achilleas wrote:MAN!!! You just gave a GREAT idea!!! An Object to know the name and type of the variable it is pointed to. Or to be more specific a list of all variables which point to it!!
Achilleas please permit me laugh first... , the idea started from the rancher that started this thread 'Hama Kamal', we could 'propose' that to the new onwers of java 'Oracle'..."We want objects to identify variables that refer to them"