The
toString
method is defined in the
java.lang.Object
class and returns the object class name and its internal address:
The
java.util.Objects
class provides utility methods to get the string value code of an object:
The
java.util.Arrays
class provides utility methods to get the string value of an array of objects
(including specific overloaded methods for each primitive type).
It also provides a utility method to get a deep string value of an array of objects (array of arrays).
The following is a sample code that show how to implement the
toString
method.
-
Superclass "P":
-
Subclass "C":