• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

equlas()

 
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



i got the lin1 execution.i have a doubt in line2.

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.
 
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
>>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.
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
rubbery bacon. rubbery tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic