Dear friends,
You are given the class file for a class called Sssh. However, you do not have the source code or any information about the internals of the Sssh class. You do know that the class has a protected int variable called i. What does the following application print out?
1. class Mine extends Sssh {
2. int z;
int i;
3. public static void main(
String[] args) {
4. Mine m1 = new Mine(); m1.i = 5; m1.z = 12;
5. Mine m2 = new Mine(); m2.i = 5; m2.z = 12;
6. if (m1.equals(m2))
7. System.out.println("YES");
8. else
9. System.out.println("NO");
10. }
11.
12. public boolean equals(Object ob) {
System.out.println(z); // Line 1
13. if (z != ((Mine)ob).z)
14. return false; // line 2
15. return super.equals(ob); //line 3
16. }
17. }
Ans: IT IS IMPOSSIBLE TO KNOW.
problem:
1. why is the answer impossible to know.
2. Line1 access which instance of z , ie, m1.z or m2.z . I tried giving a print statement and found that it accessed m1.z(Here the values are same. I gave diff values) . Why is it is accessing m1.z value?
3. Line 2 where is this return going to (I mean it is returning to which line?)
4. Line 3 -- can there be 2 return statements.
Hi ranchers, I had made a similar posting sometime back,but couldn't understand. Please help me out.
Thanks in advance
Padmini
[This message has been edited by padmini Babu (edited June 23, 2001).]