Re: method to access the name of the object that got created.



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
.



Relevant Pages

  • Why one of the reasons to say that a design is bad is about deployment???
    ... The Rectangle class has two methods shown. ... It never draws the rectangle on the ... some computational geometry, but it definitely draws the rectangle on ...
    (comp.lang.java.programmer)
  • Re: RECT - Rectangle
    ... It seems at first glance that the Rectangle class ... >>I have a question regarding the RECT structure required for PInvoke calls. ... I would create the RECT structure definition ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Creating a visual object
    ... You need a retained mode graphics system which you can then use to create simple elements such as Rectangle etc which persist information and which you can use to build up useful classes of shapes and functions. ... I need the bar objects to have certain properties like height, width, colour etc. Sounds like a rectangle to me. ... I thought of inheriting the rectangle class but it seems this is only a class that holds values, ... Must I use a control template to do this? ...
    (microsoft.public.dotnet.framework.drawing)
  • Create custom rectangle UI Element
    ... I want to create a custom UI element which will be a custom rectangle object ... I'm new to XAML and c# as most of my experience ... fancy shapes so I'll just start with a rectangle class where I can add ...
    (microsoft.public.dotnet.general)
  • Re: How can I determine size of popup window based on text assigned to body?
    ... >I tried calling getBoundingClientRect(), but the resulting rectangle size is ... I think it is because the popup object has no size until you call ...
    (microsoft.public.scripting.jscript)