1.ob2.equlas() means deep comparision.but here ob2 is obj2 object and having no value.and oba is obj1 objeact and having values (1,2).how come the result true is displaying.
2.How come the lin3 is not showing any classcastException
Thanks in advance.
Meena R. Krishnan
Ranch Hand
Joined: Aug 13, 2006
Posts: 178
posted
0
>>1.ob2.equlas() means deep comparision.but here ob2 is obj2 object and having no value.and oba is obj1 objeact and having values (1,2).how come the result true is displaying.
..is because, you are initializing it to 1 and 2 in the class declaration of obj2. Try changing the defaults to different values in obj2 and see what happens.
>>2.How come the lin3 is not showing any classcastException Why? In the class obj2, as per your code, at line 3, it is expecting an object of type obj1 and in the main() you are passing obj1, therefore no exception. At line 2, try passing ob2 instead and you will see the exception.
Keith Lynn
Ranch Hand
Joined: Feb 07, 2005
Posts: 2341
posted
0
In the obj2 class, you have two instance variables that are initialized when an object of type obj2 is created.
In this case you initialize them to 1 and 2.
These are the same values of the variables in the obj1 object you send.
The reason there isn't a ClassCastException is that you are converting the reference to type obj1, and you are send a reference of type obj1 to the equals method.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.