There is a question which was recently asked to me in an interview.
Problem: There is a class meant to profile the execution time of the code. The class
Throwing an exception when the methods are not called in the correct order is common. For example, Thread
's start
will throw an IllegalThreadStateException
if called twice.
You should have probably explained better how the instance would know if the methods are called in the correct order. This can be done by introducing a state variable, and checking the state at the start of each method (and updating it when necessary).