This is a question that many interviewers ask, and one you can expect during the behavioral portion of the interview.
The purpose of this question ISN’T to find out if you would do something illegal if your boss ordered you to, but it’s actually asked in order to determine your reaction. After all, being asked by a direct superior to do something you disagree with can be quite conflicting. On the one hand, you want to do what you are asked in order to comply with the boss’ orders. On the other hand, you have principles and beliefs you may not want to compromise and you certainly don’t want to do anything illegal or unethical just because your boss asks you to.
Your answer should reflect this, and you can give an answer along the lines of:
"It would depend on what I am being told to do. Let’s say you ask me to do something that I strongly disagree with on moral grounds. I would explain my beliefs and principles to you, and I would try to find a solution that we both agree with. I would try to understand the reasons for doing what I am being asked to do, and come up with an alternative for what I am being asked to do.
If the task is directly against my beliefs or morals and yet you insist that I comply with your request, I would be forced to decline. I could bring the matter to Human Resources for meditation, with the ultimate goal of doing what needs to be done WITHOUT compromising my beliefs and morals.
If, however, I am being asked to do something illegal, I would immediately report the matter to the proper authorities. There is never any reason to do something illegal, and it is our job as employees and professionals to follow the rules and regulations of both our company and the organizations that govern our industry."
This is a long answer, and it’s one that you should adapt into your own words. The central message, however, should remain the same.
You need to make it clear that you are willing to do whatever needs to be done, but you are a person with principles who will not hesitate to take action should anything unethical, immoral, or illegal be asked of you.
One thing to keep in mind: many companies are actively looking for people who have grey moral boundaries. They don’t want someone who is so "white-knight" and honest, so there’s a very real possibility that you will NOT get the job with this answer.
However, if you don’t get the job because you gave this honest answer, it was a job that you didn’t want. You should never find yourself being asked to do something that you strongly disagree with on moral or ethical grounds, so any job that asks you to do otherwise is one you want to pass on!