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...
anamika henry
Ranch Hand
Joined: Mar 09, 2007
Posts: 30
posted
0
thank you moon, i could understand now
tirapa reddy
Greenhorn
Joined: May 05, 2007
Posts: 19
posted
0
hi m1 is assigned with m how it becomes null ?
David Grant
Greenhorn
Joined: Apr 01, 2008
Posts: 13
posted
0
m1 is instantiated using the no-arg constructor, Mixer(), which leaves the m instance variable unchanged from its initial value of null.
Niranjan Deshpande
Ranch Hand
Joined: Oct 16, 2005
Posts: 1277
posted
0
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.