0

I created a shape object in java which has attributes color, corners and name. I then have a method create shape that return a Shape object. I have for instance create a circle. What I need to do is return a string of the object for example shape.toString() needs to be:

Circle[c=Blue,cnr=0]:cirleName

but I am getting:

com.shape.model.Circle@64fa8cc6
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
Andre Coetzee
  • 1,260
  • 3
  • 20
  • 34

1 Answers1

6

You need only to rewrite the method toString(). Please verify the signature of this method.

public String toString() {
    return "Circle[c=" + color + " ,cnr= " + cnr + "]:" + cirleName;
}
Davide Lorenzo MARINO
  • 26,420
  • 4
  • 39
  • 56
  • thanks for the reply. This works! is there anyway to get the class name of the object as Circle and not class com.shape.model.Circle because at the moment I am returning as class com.shape.model.Circle[c=Blue,cnr=0]:circleName – Andre Coetzee Mar 07 '15 at 20:14
  • To get the class name without a package you can use the following code Circle.class.getSimpleName() – Davide Lorenzo MARINO Mar 07 '15 at 20:16