• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

IF...ELSE

 
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there any particular reason you added the final keyword in the main method header?
 
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If your first condition evaluate to true, the "else" won't be evaluated.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic