We know that, if n different things are arranged in a row,
then the number of ways in which they can rearranged so that none of them occupies its original place is n!(1−11!+12!−13!+...+(−1)nn!)
Now assume that each boll is placed in the box of its own choice and apply the above result
Hence the required number of different ways is
4!(1−11!+12!−13!+14!)=4!2!−4!3!+1
=12−4+1=9