Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why doesnt this compile?

 
rohan yadav
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Why the compiler is giving compiler error??
This question from ExamLab
 
Raju Champaklal
Ranch Hand
Posts: 521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
s1==s2+","+s2 will give false....and then you are comparing a boolean with a string which is illegal
 
Rafael Angarita
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes!...Try enclosing the string comparisons between parenthesis and see what happens!

 
Raju Champaklal
Ranch Hand
Posts: 521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is because + comes higher in the table than == so first the strings are added and then compared....you get a boolean...and then boolean is compared with a string which is illegal?

understood man?

nice question by the way....this helped clear my concept of the table
 
rohan yadav
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Understood now:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic