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
-
In Class Outline, right-click the name of the class that will define the method. On the shortcut menu, click Add Method.
-
In the Add Method dialog box, enter the name of the method in the Method Name box.
-
Select a return type from the Return Type drop-down list or enter your own return type.
-
To add method parameters, click the ellipses (...) button under Parameters:
-
In the Edit Parameter List dialog box, select a parameter type from the Type drop-down list or enter your own type. In the Name box, enter the name of the parameter.
-
Click Add to add the parameter.
-
Repeat this process for each method parameter. Note that to delete a parameter that you have already added, you can select the parameter from the list and click Delete. To insert a parameter between two existing parameters, select the parameter after which the new parameter is to appear. When you click Add, the new parameter is inserted before the parameter you selected.
-
Click OK when you have finished adding all parameters.
-
Select an access modifier from the Access drop-down list. Methods can be declared as public, protected, private, or default (package).
-
Select additional modifiers, such as abstract, final, static, synchronized, or native.
-
To insert Javadoc comments for the method, enter the comment text in the Javadoc comment box.
-
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
-
In Class Outline, right-click the name of the class that will define the member variable. On the shortcut menu, click Add Member Variable.
-
In the Add Member Variable dialog box, enter the name of the member variable in the Member Variable Name box.
-
Select a data type from the Data Type drop-down list or enter your own data type.
-
Select an access modifier from the Access drop-down list. Member variables can be declared as public, protected, private, or default (package).
-
Select additional modifiers, such as static, final, volatile, or transient.
-
To initialize the member variable, enter a value in the Initial Value box.
-
To insert Javadoc comments for the member variable, enter the comment text in the Javadoc comment box.
-
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
-
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.
-
On the shortcut menu, click Add Class.
-
In the Add Class dialog box, enter the name of the class in the Class Name box.
-
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.
-
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).
-
Select additional modifiers, such as abstract, final, or static. (Only nested classes can be declared as static.)
-
To insert Javadoc comments for the class, enter the comment text in the Javadoc comment box.
-
Click Add to insert the class declaration into your file. Class Outline is automatically updated to display the new class.