First, lets have a look at the Mixer class. It has one instance variable m1 of type Mixer and go() method.
In line 4, m2 is a mixer object created at line 1 and that time m1 is initialized with null. Since m1 is also a Mixer, it can be assigned in m5 but as m1 is null m5 is also null. So, when you are calling the go() method on a null object(m5) JVM is giving a NullPointerException.
Hope, I could make you understand...
Joined: Mar 09, 2007
thank you moon, i could understand now
Joined: May 05, 2007
hi m1 is assigned with m how it becomes null ?
Joined: Apr 01, 2008
m1 is instantiated using the no-arg constructor, Mixer(), which leaves the m instance variable unchanged from its initial value of null.
Joined: Oct 16, 2005
yes it will throw a null pointer exception..
SCJP 1.4 - 95% [ My Story ] - SCWCD 1.4 - 91% [ My Story ] Performance is a compulsion, not a option, if my existence is to be justified.