Adding a New Declaration

See Also

You can use Class Outline to add a method or member variable to a class, or to add a new class to your .java file.

Note   If you use the Text editor to add a declaration, the item is automatically added to Class Outline.

To add a new method

  1. In Class Outline, right-click the name of the class that will define the method. On the shortcut menu, click Add Method.

  2. In the Add Method dialog box, enter the name of the method in the Method Name box.

  3. Select a return type from the Return Type drop-down list or enter your own return type.

  4. To add method parameters, click the ellipses (...) button under Parameters:
  5. Select an access modifier from the Access drop-down list. Methods can be declared as public, protected, private, or default (package).

  6. Select additional modifiers, such as abstract, final, static, synchronized, or native.

  7. To insert Javadoc comments for the method, enter the comment text in the Javadoc comment box.

  8. Click Add to insert the method declaration into your file. Class Outline is automatically updated to display the new method.

To add a new member variable

  1. In Class Outline, right-click the name of the class that will define the member variable. On the shortcut menu, click Add Member Variable.

  2. In the Add Member Variable dialog box, enter the name of the member variable in the Member Variable Name box.

  3. Select a data type from the Data Type drop-down list or enter your own data type.

  4. Select an access modifier from the Access drop-down list. Member variables can be declared as public, protected, private, or default (package).

  5. Select additional modifiers, such as static, final, volatile, or transient.

  6. To initialize the member variable, enter a value in the Initial Value box.

  7. To insert Javadoc comments for the member variable, enter the comment text in the Javadoc comment box.

  8. Click Add to insert the member variable into your file. Class Outline is automatically updated to display the new member variable.

To add a new class

  1. To add a nested class, right-click the name of the containing class in Class Outline. To add a top-level class, right-click any class or the Class Outline window itself.

  2. On the shortcut menu, click Add Class.

  3. In the Add Class dialog box, enter the name of the class in the Class Name box.

  4. To make this class a nested (or inner) class of the class that is selected in Class Outline, select the Create a nested class option. For information about nested classes, see Inner Classes in the Java Language Specification.

  5. Select an access modifier from the Access drop-down list. Top-level classes can be declared as public or default. Nested classes can be declared as public, protected, private, or default (package).

  6. Select additional modifiers, such as abstract, final, or static. (Only nested classes can be declared as static.)

  7. To insert Javadoc comments for the class, enter the comment text in the Javadoc comment box.

  8. Click Add to insert the class declaration into your file. Class Outline is automatically updated to display the new class.