I didn't understand how the result for the following code is hi,hi and exception. How could m2 objects m1 is never intialized... Pls give me an explanation.
Did you initialize m2's m1 by passing mixer object to constructor argument? By default m1 is null so as m2's m1 is set to null. Therefore accessing an instance method using m2.m1 yields exception (NullPointerException)
When mixer object for m2 is created, the instance variable m1 is null. When mixer object m5 is assigned the value m2.m1, it is assigned a value of null. Then m5 attempts to invoke the go() method on a null object. So you get a NullPointerException.