Moving a Class Member to a Superclass

See Also

You can use the Pull Up command to move methods and fields to a class that their current class inherits from.

To initiate the Pull Up operation:

  1. In the Source Editor or Projects window, select the class that contains members that you want to move.
  2. Choose Refactor > Pull Up.

    The Pull Up dialog box appears and displays a list of the class's members and any interfaces that the class implements.

  3. In the Destination Supertype drop-down list, select the class that you want to move the members to.
  4. Select the checkbox for the member or members that you want to move.

    If the current class implements any interfaces, there are checkboxes for these interfaces. If you select a checkbox for an interface, the implements statement for that interface is moved to the superclass.

  5. (Optional) If you want to make a method abstract, select the Make Abstract checkbox for the method. If you select this checkbox, the method will be declared in the superclass as an abstract method and overridden in the current class. The method will be assigned the protected access modifier.
  6. If you click Refactor, the IDE applies the changes automatically and skips the remaining steps. If you click Preview, the Refactoring window displays the lines of code that will be changed. Review the list and clear the checkbox of any code that you do not want changed. If the class that you are pushing members from has multiple subclasses and you do not want the members to be pushed to all of them, be sure to clear the checkboxes for the corresponding subclasses. Click Do Refactoring to apply the selected changes.
See Also
Refactoring: Quick Reference
Moving an Inner Class One Level Up
Moving a Class Member to a Subclass
Moving a Class to Another Java Package
Extracting a Superclass
Renaming a Class or Interface
Undoing Refactoring Changes

Legal Notices