File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Please Explain Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Please Explain" Watch "Please Explain" New topic
Author

Please Explain

Thirumalai Muthu
Ranch Hand

Joined: Oct 07, 2007
Posts: 75
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


SCJP 5
Robert Elbourn
Ranch Hand

Joined: Oct 15, 2007
Posts: 69
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
 
subject: Please Explain
 
Similar Threads
explain output
understand me this code(m3.m1 and m2.m1)
K & B question ???
Question
what really it mean's