• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

assignment operator : doubt.......

 
Ranch Hand
Posts: 485
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
char c = 65;
double d = 10;
if(c==d)


i doubt how two different type are compared. Though it is a basic doubt i want some one to explain me about this....
 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

U can compare the two different type.
If both r compatible it returns true.



So, in your code char and double r incompatible.

hope u got it.
 
Parameswaran Thangavel
Ranch Hand
Posts: 485
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
thank u for ur reply

is the following code legal???

Object a = "hello";
String b = "hello";
if(a == b)
System.out.println("equal");
else
System.out.println("not equal");
 
Sakthi Kani
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi paramesh




This is legal it gives the result as equal.Both object reference has the same hashcode, because both value r same.

Check the following code to understand



Now in this case, it has differnet hashcode.
 
Parameswaran Thangavel
Ranch Hand
Posts: 485
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can i say on using == the both operands should belong to the same hierarchy..
 
Sakthi Kani
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes.

whenever u get doubt, first u try it out with small sample program.
Even then, u can't understand then post it. Because trying yourself will help u more than others explanation.
reply
    Bookmark Topic Watch Topic
  • New Topic