This is based on the principle of "like dissolves like". Ethyl alcohol and water are both polar in nature, and thus are of same type. So they mix uniformly and produce a homogeneous solution. Oil and water, on the other hand are of opposite nature as water is polar but oil is non-polar. So, they do not mix and a layer separates them in the solution. So, they form a heterogeneous solution.