Here's how it works:
* Friction: The rubbing creates friction, which causes the atoms on the surfaces of the objects to bump into each other.
* Electron Transfer: This bumping can cause electrons to be knocked loose from one object and transferred to the other.
* Static Charge: The object that gains electrons becomes negatively charged, while the object that loses electrons becomes positively charged.
This process is called triboelectric effect, and it's the reason why you get static shocks when you walk across a carpet or rub a balloon on your hair.