Null reference in java
<p>I have a piece of code for which i have to know how memory is allocated</p>

<pre><code>public class Demo {

public void checkNullReference(){
    ConsumerName name =  null;
    addReference(name);
    System.out.println(name.getConsumerName());
}

public void addReference(ConsumerName name){
    name = new ConsumerName();
    name.setConsumerName("KRISHNA");
}

public static void main(String []args){
    Demo demo = new Demo();
    demo.checkNullReference();
}
}
</code></pre>

<p>The code is giving null pointer exception i have given a refrence of object to method and there i am allocating new object to it and setting name  if i rewrite the method then every thing is working as expected</p>

<pre><code>public void checkNullReference(){
    ConsumerName name =  new ConsumerName();
    addReference(name);
    System.out.println(name.getConsumerName());
}
</code></pre>
