To create a user defined class type, the following steps are usually needed:
- Choose an appropriate name for your class type
- Begin with the syntax for a class:
public class the_class_name_you_chose { }
- Decide what instance and/or static methods your class type will have.
- Decide what variables you will need in the class for each instance to "remember" and use between calls to its methods.
- Write one (or more) constructors for your class.
A constructor executes when an instance of your class is created using the new operator.
A constructor's purpose is to properly initialize the member variables before any of the methods are called.
- Write the methods.
- Write a separate class with a main method to test your new class type.