If alternating current is used instead of direct current then the core of electromagnet will get magnetized, but the polarity at it’s ends will change. Since attraction of armature does not depend on the polarity of electromagnet, so the bell will still ring on pressing the switch.