This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
can any one please explain me the line 6,7,9 and 11
Line 6: You are calling a static method FizzSwitch() passing f1 and f2 to it.
Line 9: Nothing special here, simple static method signature. If you are getting confused with final parameter, no problem, make then both final, it will be accepted but inside the method you can't dereference them.
Line 10: Another reference variable z of type Fizz is created that is final, means can't be dereferenced once referenced. You set its reference to the x, that is f1 in main;
Line 11: You set the value of x to 6 hence references can be final, objects can't be. You can change the internal state of an object as you did by changing the value of x to 6. You returned the z;
Line 7: Now what is returned from FizzSwitch() method, you assigned to f3. Now you know f3 and f1 are referring to same object on the heap. They are == (referring to same object) and their value x is ==.
Hi, Here the Z is declared as final type and it is refernced to X=5 and in the next line it is given Z.X=6.Does it allow the final varibles to be reassgined a value after declaring it final??? actually tell me the exact o/p of the program.Its bit confusing. Regards, Lalitha.
Joined: Feb 28, 2007
You mistake is: Fizz f3 = new FizzSwitch(f1,f2);
remove "new" from that line! FizzSwitch is not a class, it is a static method.
Original post had this error, i modified that code, then answered.
Did you get that?
Joined: Apr 16, 2006
Hey, thanks chandra. It was really a silly mistake.