• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

IF...ELSE

 
Thomas Markl
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

C:\Java\EigeneJavaProgramme>java ZombieStomp
Killer Of Giants
Symphony of Destruction
If str = „markl“ then (str instanceof String) is true
AND (str instanceof Object) is true.
Why doesn’t it print:
Killer Of Giants
I Shot the Sheriff
Symphony of Destruction
 
Marilyn de Queiroz
Sheriff
Posts: 9067
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


If str = „markl“ then (str instanceof String) is true
AND (str instanceof Object) is true.
Why doesn’t it print:


Killer Of Giants
I Shot the Sheriff
Symphony of Destruction


because of the 'else'. Read --

if str is an instance of string => print Killer Of Giants

or else if string is not an instance of string but is an instance of Object => print I Shot the Sheriff

then always print Symphony of Destruction
 
James Chegwidden
Author
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any particular reason you added the final keyword in the main method header?
 
Younes Essouabni
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your first condition evaluate to true, the "else" won't be evaluated.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic