Sort of the same....
If I wish to listen to online music I can either use my speakers or plug in a set of headphones. If I wish to use speakers when I listen to CD's then I must set the Audio Playback device to my speakers. To use headphones I must either change the audio Playback device to a different audio port or plug into the headphone port on the speaker.
If you use Program A and want Audio Device A to be used then the first option would normally be some default setting in Program A configuring/assigning the use of Audio Device A.
Likewise for Program B and Audio Device B. The assignment would be via the program default or configuration settings, if any, in the respective programs. E.g., headphones versus speakers. But...