Usually we will create a class in one file, and then use it in a separate file. Look at the class file for State and the file that uses it.
This example was made as simple as possible just for illustrations. We will give another example, length, that is more complete. Try the example, then look at length and notice that it has one property, length, a constructor, and methods setLength, getLength, centimeters and toString. Look at the text version of the example to see how the length class is used. Notice that the value of length cannot be negative.
The next example creates a Fraction class with a numerator and a denominator. The first creates a half, the second lets the user enter a numerator and denominator. Because we do not allow the denominator to be negative, we do not have to test for zero when we find the decimal value of the fraction. Text of half, text of second example.