Depends on HOW you animated. If you animated things by drawing frame by frame, then no it can not be transferred. If however you have a rigged character than the animation will for obvious reasons move from rig to rig since they are either identical or can be made equivalent. No guarantees it will work well or easily though.
my animation teacher and told me that this is only possible with 3d animation, is that true?
Depends on how you define 3D. For obvious reasons all 3D animation software are capable of doing 2D animation. So no its not entirely true, however probably true enough for a lie to children.
Simply the transferability is not dependent on the type of software used but rather do you depend on direct manipulation of data or indirect manipulation. Indirect manipulation means some sort of rig that can be shared across assets.
what program is the best to do it?
Best is not defined. Its a optimization problem and i can not optimize with this info. Usually a tool you know how to use.