March 2002
Intermediate to advanced
496 pages
8h 51m
English
| SOLUTION 16.1 | Many answers are possible, but toString() is probably the most commonly used method that creates a new object. For example, the following code creates a new String object:
String s = new java.util.Date().toString(); The creation of strings often happens behind the scenes. Consider: System.out.print(new Date()); This method creates a String object from the Date object, ultimately by calling the toString() method of class Date. It is interesting to walk through this in debugger, to see the details of what happens within a common print() method. Another method that creates a new object is clone(). You may discover other methods that are “factories” for creating objects without necessarily exemplifying ... |
Read now
Unlock full access