You know you are required to tell me you're a police officer, right?
Wrong. Despite popular belief to the contrary, the police are not required to answer this questions honestly. Of course, they and often do announce their status as police officers. For instance, when serving a warrant, the police will say who they are, the agency they work for, and the reason that they are making contact with an individual. If, on the other hand, an undercover officer approaches a suspected drug dealer and asks him if he can purchase some drugs, the officer would not be required to tell the drug dealer that he was a police officer if the drug dealer asked him. Just remember, the officer is undercover—they are not supposed to appear to be police officers and are making efforts to conceal their appearance. They do not need to give their identities away to those who ask for them.
Of course every case is different, so if you have any question about the nature of a recent interaction you had with a police officer or any law enforcement official, you should contact an attorney.