Objects Creating Objects

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   hear noise   go to next page

Answer:

No. Running a String object's method does not change that object, but creates a new String object.

Objects Creating Objects

It seems a little odd that an object can create another object. This is not how real-world objects usually behave. Bricks do not create other bricks. Cars do not create other cars. But some real-world objects, animals and other living things, can create other new objects through a complicated process that involves following instructions contained in DNA.

The substring() method of a String object creates a new object by asking the Java virtual computer to create a new object. The virutal computer creates the new object in the usual way by following the instructions contained in the class.

QUESTION 13:

Do you imagine that there are other String methods that create new String objects?