File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please Explain

 
Thirumalai Muthu
Ranch Hand
Posts: 75
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class Mixer
{
Mixer(){}
Mixer(Mixer m) {m1=m;}
Mixer m1;
public static void main(String [] args)
{
Mixer m2=new Mixer();
Mixer m3=new Mixer(m2);
m3.go();
Mixer m4= m3.m1;//line1
m4.go();
Mixer m5= m2.m1;
m5.go();//line4
}
void go() { System.out.print("hi");
}
}

Can anyone Please explain the lines from 1 to 4.Thanks
 
Robert Elbourn
Ranch Hand
Posts: 69
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class Mixer
{
Mixer(){}
Mixer(Mixer m) {m1=m;}
Mixer m1;
public static void main(String [] args)
{
Mixer m2=new Mixer();
Mixer m3=new Mixer(m2);
m3.go();
Mixer m4= m3.m1;//line1 - m4 is created using m1 as a parameter (not null)
m4.go(); - this is invoked
Mixer m5= m2.m1; - m5 is created using m2.m1 which is null!!! as m2 was created using a direct call without passing a parameter as m2.m1 returns a null value then m5 is null
m5.go();//line4 - any method on a null returns my favourite exception (nullpointer exception)
}
void go() { System.out.print("hi");
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic