I've seen this often, and as long as the student dwarfs have nonzero experience in that weapon, they gain experience in the skill being demonstrated.
In fact, one way I wind up getting my militia trained in multiple weapon skills (I always train marksdwarfs in hammering) is to start all prospective markdwarfs in the hammer squad, and, as soon as they get some experience (not yet first level, but just a bit of experience) transfer them to a crossbow squad captained by a legendary hammerdwarf. I'd wind up with reasonably skilled hammering marksdwarfs fairly soon after improving their skills from demonstrations alone.
The caveat is that, if the potential student dwarf has absolutely zero experience, they will not even watch demonstrations (I think).
Strange news everyone!
https://imgur.com/Vos6h4K
I don't know how (un)important that might be, but I just found out that dwarves can (and will) perform weapon demonstrations without having the actual weapon equipped. On the example above, the higlighted dwarf is the one leading a warhammer demonstration and as can been seen he has no weapon equiped on himself. In fact there isn't a single warhammer in this fort.
Probable factors:
1. The squad's uniform consists of just a "war hammer" and is set to "over clothing".
2. One of the soldiers (eshtan stigazid in the photo) had lvl 1 hammerdwarf before joining the squad. The rest started with no weapon skills.