Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is the answer

 
nikunj thakur
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 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 Mixer.java
Mixer.java:3: cannot find symbol
symbol : variable ml
location: class Mixer
Mixer(Mixer m) { ml = m;}
^
1 error

E:\kb>

What is write
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by nikunj thakur:
...
Mixer.java:3: 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;
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic