Yes you need to have the two classes in a class diagram to add the inheritance or other relations between them. After that you can remove one or the two classes, or the diagram itself, if you don't want to show the relation in a diagram.
Let's remark you can also write a
plug-out to add the inheritance without having to use a diagram, in this case the
plug-out will be applied for instance on the inheriting class and the inherited class may be marked to simplify the implementation of the
plug-out and minimize manual manipulations
