After the following statements have executed,

String str = new String("alphabet soup");
int    len = str.length();

what value is in the variable len?

A good answer might be:

13. (Remember to count the space character.)


Parameter-less Methods

Look again at the method call (the second statement, which uses "dot notation" to specify the method.)

String str = new String("alphabet soup");
int    len = str.length();
              |     |   |
              |     |   +---- a parameter list with no parameters
              |     |
              |     +---- the name of the method that is to be run
              |
              +---- the reference to the object that contains the method

The second statement contains a method call. This is a request to run a method of an object. The object referenced by str contains a method length() which, when called, returns the number of characters in the string.

The length() method does not require any parameters. The parameter list in the method call str.length() is empty.

QUESTION 2:

What is wrong with the following code segment?

Point myPoint = new Point();  // construct a point at x=0, y=0
myPoint.move();               // move the point to a new location