Re: method to access the name of the object that got created.
- From: Gordon Beaton <n.o.t@xxxxxxxxx>
- Date: 28 Feb 2007 12:13:58 GMT
On 28 Feb 2007 02:43:23 -0800, Saiprasad wrote:
What method/property should I call in the place of "METHOD?" in
"printRectangle" above so that
If R1 is a object of Rectangle class with width 20, on calling
"R1.printRectangle()" it should print out
"R1Is having a width of 20"
What should it print in the following cases?
void someMethod(Rectangle r) {
r.printRectangle();
}
Rectangle r1 = new Rectangle(...);
Rectangle r2 = r1;
r1.printRectangle();
r2.printRectangle();
someMethod(r1);
someMethod(r2);
In other words, there is no property of the object that will give you
the information you are looking for. If you want to give names to your
objects, you need to add fields to the class and should probably
override toString() as well.
/gordon
--
[ don't email me support questions or followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
.
- References:
- method to access the name of the object that got created.
- From: Saiprasad
- method to access the name of the object that got created.
- Prev by Date: Re: new to everything
- Next by Date: Re: Disable ESC on JOptionPane
- Previous by thread: method to access the name of the object that got created.
- Next by thread: Re: method to access the name of the object that got created.
- Index(es):
Relevant Pages
|
|