File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes what is the answer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "what is the answer " Watch "what is the answer " New topic

what is the answer

nikunj thakur
Ranch Hand

Joined: Sep 23, 2007
Posts: 47
class Mixer {
Mixer() { }
Mixer(Mixer m) { ml = m;}
Mixer m1;
public static void main(String[] args) {
Mixer m2 = new Mixer();
Mixer m3 = new Mixer(m2); m3.go();
Mixer m4 = m3.m1; m4.go();
Mixer m5 = m2.m1; m5.go();
void go() { System.out.print("hi "); }

What is the result?


hi hi

hi hi hi

Compilation fails

hi, followed by an exception

hi hi, followed by an exception
answer is this

F is correct. The m2 object's m1 instance variable is never initialized, so when m5 tries to use it a NullPointerException is thrown.

but i am getting this

E:\kb>e:\jdk1.5.0\bin\javac cannot find symbol
symbol : variable ml
location: class Mixer
Mixer(Mixer m) { ml = m;}
1 error


What is write
marc weber

Joined: Aug 31, 2004
Posts: 11343

Originally posted by nikunj thakur:
... cannot find symbol
symbol : variable ml
location: class Mixer...

You have a typo. In the third line, you typed "ml" using lowercase letters "M" and "L". But the lowercase 'L' should be the number '1' to match the variable declared on the following line...

Mixer(Mixer m) { m1 = m;}
Mixer m1;

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
I agree. Here's the link:
subject: what is the answer
It's not a secret anymore!