0

Is it possible to return the name you gave to a Rectangle object when you created it? For example:

Rectangle f = new Rectangle();
f.getName() \\would return "f"
sunkuet02
  • 2,376
  • 1
  • 26
  • 33
Cora Coleman
  • 237
  • 1
  • 5
  • 14
  • Look for Java reflection – Khaled Oct 22 '16 at 22:15
  • 1
    No. `f` is a local variable in this code snippet. The name of the variable is not part of the object, and cannot be accessed at runtime. (What would you expect to get, for example, if you had two references to the same object?) – James_D Oct 22 '16 at 22:47
  • The other thing to point out here is that in your suggested code, you could - trivially - replace `f.getName()` with `"f"`. While that may seem facetious to point out, there are *no* meaningful contexts in which the same statement isn't true. Probably here you need to actually explain what it is you're really trying to do. – James_D Oct 23 '16 at 02:54

0 Answers0